Google Analytics Data for Particular page - google-analytics-api

I have integrated Google Analytics. I want to fetch the data for a particuar page. I have got data for many pages. But I am not getting data for some pages I need. Though, that page is shown in Google Analytics Reporting area. Can anyone suggest the reason ?
$params = array( 'metrics' => 'ga:visits,ga:socialInteractions,ga:pageviews,ga:bounces,ga:uniquePageviews' , 'dimensions' => 'ga:pagePath' , 'ga:pagePath=#/c14z8', );
$visits = $ga->query($params);

Related

How to create multiple adsets using facebook marketing api

I am trying to target multiple lat-long(more than 200). There is a option of multiple ad sets in Facebook power editor but how to achieve this with Facebook Marketing API using curl. After doing a lot of research found this
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign
but it's just showing multiple adsets information and except this I did not found any other explanation on facebook marketing api doc to create an ad using multiple ad sets.
Couldnt comment under 50 :)
Here is your solution :
https://developers.facebook.com/docs/marketing-api/buying-api/targeting/
EDIT: if you want to create multiple ads this video will help you :
https://www.youtube.com/watch?v=pq1y_Ze-0g8
if you want to target multiple with lat and long.
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
$result = TargetingSearch::search(
TargetingSearchTypes::GEOLOCATION,
null,
'un',
array(
'location_types' => array('country'),
));
for more info :
https://developers.facebook.com/docs/marketing-api/targeting-search/

Facebook "Boost Post" through API?

I've been crawling through the documentation and found out that it IS possible to achieve a "Boost Post" functionality through the Facebook Ad APIs. However, I have had some trouble finding what exactly the Boost Post does? i.e. Which part of the API corresponds the "Boost Post" functionality of the Facebook UI?
https://developers.facebook.com/docs/marketing-api/adcreative/v2.4
This page outlines several types of ads. What are the types Facebook "Boost Post" button makes? Or is this wrong part of the API?
See the example for creating an ad_campaign here: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#Creating
The object (page post in this case) you're trying to promote is set as the promoted object.
You can also set the lifetime or daily budget of the ad at the campaign level.
From the Facebook docs,
For creating an ad from Page post ( boosting a post ), you will first need to create the creative for that ad from the post.
See the doc page on how to create ad adcreatives. Search for Create an ad from an existing page post
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Promoted Post',
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
));
$creative->create();
After that you will need to create an ad using that creative ad.
Creating ads from API with creative id
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Ad;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$access_token = '<ACCESS_TOKEN>';
$app_secret = '<APP_SECRET>';
$app_id = '<APP_ID>';
$id = '<AD_ACCOUNT_ID>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'name' => 'My Ad',
'adset_id' => '<adSetID>',
'creative' => array('creative_id' => '<adCreativeID>'),
'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createAd(
$fields,
$params
)->exportAllData(), JSON_PRETTY_PRINT);
The examples on the above are using Facebook PHP Business SDK, but you can make the calls using the Facebook PHP Graph SDK with the same parameters.
See the respective SDK files for finding the exact API parameters name.
For example : the Business SDK parameter
AdCreativeFields::OBJECT_STORY_ID is object_story_id as the API parameter.
Hope that helps
I think what you want is a "Page Post Ad". My understanding is that this is really what "Boosting a Post" creates, but in a streamlined way. Coming in through the API, there is no such streamline, so the term "Boost" doesn't get used, but there is still some pretty good documentation.
I'd start with the second paragraph of this section:
https://developers.facebook.com/docs/marketing-api/buying-api/ad-units#creative

Facebook application timeline tabs

I have a question about the timeline tabs. I have created an application which has been installed on 2 different business pages as tabs. Now what I want to do is change the content of the tab based on which business page is being viewed. Another company has done this but I can't work out how. Any thoughts?
This is pretty easy to do. If you decode the signed_request data POSTed to your page, you can see what page is 'looking' at your app (i.e. which page the app has been installed on).
If you decode the data (e.g. in PHP you can do: print_r( $facebook->getSignedRequest() ); to print the decoded version), you will see something like:
Array
(
...
[page] => Array
(
[id] => 1234567890
[liked] => 1
[admin] => 1
)
[user] => Array
(
...
)
)
The $response['page']['id'] is the ID of the Page that is looking at your app at that moment. You can store the IDs of the page that have installed your app, and check it with this to determine which content to load up.
You will also notice that the data includes $response['page']['admin'], which tells you if the user looking at the page is an admin of the page (1=admin, 0=not admin). And $response['page']['liked'], which tells you if the user looking at the page is a fan (1=fan, 0=not a fan).

Post Survey on our company facebook page using PHP SDK

Our company deals with various online contests. As a part of functionality we need to post questions with fixed options to our facebook page periodically. Any idea about how to implement this using facebook api?
You can do it using graph api. The url will be {page_id}/questions. You need to pass the question as a string and options as an array.
Below code helps you to do that using facebook PHP SDK:
$question = $_POST['question'];
$options = array($_POST['option1'], $_POST['option2'], $_POST['option3']);
$api_params = array(
'question' => $question,
'options' => $options,
'allow_new_options' => false
);
$url=$facebook->api($_POST['select-page'] . '/questions', 'POST', $api_params);
Visit this link for demo and code samples

facebook: how to show content in page only if user likes it

how can i show or display information only if the user is fan or likes my page? there are several pages that do that to catch more fans. thanks!
edit:
like the victorias secret page with this box
http://www.facebook.com/victoriassecret?v=app_117241824971601&ref=ts
My answer applies if you use an iFrame for your tab/canvas. First, you need to ask for permissions (just need basic info from user). Then, make a call to the Javascript API, like so:
FB.api('me/likes', function(response) {
});
This gives a JSON object of everything the user has liked. So, you have to loop through the response and try to find your page. If you are successful in finding it, display the awesome content!
Hope this helps!
Edit: Looking back, my answer was way off. This information is actually contained in the signed_request given by Facebook.
If you mean Facebook Page, use functions from Facebook API: Signed Request
$signed = parse_signed_request($_REQUEST['signed_request'], YOUR_APP_SECRET_KEY);
$signed = Array (
[algorithm] => HMAC-SHA256
[expires] => 13..
[issued_at] => 13..
[oauth_token] => ...
[page] => Array (
[id] => 29...
[liked] => 1
[admin] =>
)
[user] => Array ( [country] => cz [locale] => en_US [age] => Array ( [min] => 21 ) )
[user_id] => ..
)
If current user like your Facebook tab page, you find out from $signed['page']['liked']
If you're using the php sdk, you can use a call to the facebook object api and then determine if they have the like you want them to have.
$path = 'me/likes';
$likes = $facebook->api($path);
More info here
This is a privacy and security setting. Facebook Privacy FAQ
Page Tabs gets Signed Request that contain "liked" field
http://developers.facebook.com/docs/authentication/signed_request/
FQL isFan
http://developers.facebook.com/docs/reference/fql/page_fan/
Old REST API isFan
http://developers.facebook.com/docs/reference/rest/pages.isFan/
Legacy FBML isFan
http://developers.facebook.com/docs/reference/fbml/visible-to-connection/
There doesn't have to be any code involved. Just create a landing page (you could create a jpeg photo and link to the photo) and set that as the default landing page in your page settings. For users who are fans they go directly to the wall posts. All other people (non-fans) go to your specified landing page.
By the way, you realize that people can still access your content by just clicking on one of the tabs, correct? Even the Victoria Secrets example allows you to click on the "wall" tab, for example, and see the content.
A lot of people just like the page because it's the default landing page and they "think" they have to like the page first. It's more social psychology than anything else.
Google for Facewall Script, that should do what you want. But keep in mind to offer an option for users that not have Facebook Account.