Access Additional Standard Event Parameters using FB Graph API Explorer - facebook

I've installed Facebook Pixel on my website, and it records purchases made on my site. The script on my site is the normal purchase standard event:
fbq('track', 'Purchase', {value: '0.00', currency: 'USD'});
Except that the 'value' is dynamic and changes for each order. I want to access these additional parameters using the FB Insights API (accessed through the Graph API Explorer).
Right now, my query looks like this:
act_1020149xxxxxxxxxxx/insights?level=ad&action_report_time=conversion&default_summary=true&fields=actions,spend,account_id,campaign_name,ad_name,adset_name,impressions&time_range[since]=2015-11-01&time_range[until]=2015-12-01
This returns data that looks like this:
{
"data": [
{
"actions": [
{
"action_type": "link_click",
"value": 19
},
{
"action_type": "offsite_conversion.fb_pixel_purchase",
"value": 1
},
{
"action_type": "offsite_conversion.fb_pixel_view_content",
"value": 19
},
{
"action_type": "post_like",
"value": 88
},
{
"action_type": "page_engagement",
"value": 107
},
{
"action_type": "post_engagement",
"value": 107
},
{
"action_type": "offsite_conversion",
"value": 20
}
],
"spend": 5.16,
"account_id": "10201496xxxxxxxxxx",
"campaign_name": "Link Clicks to Website (CPC)",
"ad_name": "[2015/11/27] New Arrivals",
"adset_name": "Custom Audience - Visitors or Lookalike - Visitors",
"impressions": "2634",
"date_start": "2015-11-01",
"date_stop": "2015-12-01"
}, ...
As you can see, the query returns purchases made on the site (offsite_conversion.fb_pixel_purchase) that came from the ad. How can I extend this query to also include the 'value' and 'currency' of each purchase, as captured in the standard event code embedded on my website.
If this isn't possible, then what part of the API should I use to find that data on purchases that I'm looking for?

You need to add the 'action_values' field to get the purchase value. The currency is the one you have registered with you account. If you report different currencies for different purchases (pixel fires) I would suppose that facebook convert the values to your currency.

Related

How to further filter Facebook Graph API query on Graph API Explorer for my ad account?

I'm trying to get the ad spend and mobile app installs for my app using the Facebook Graph API v2.11 for marketing. In the Graph API Explorer, when I try
/act_<my account>/campaigns?fields=insights{actions,spend}&time_range={'since':'2017-07-07','until':'2017-12-12'}
In the output, under "insights", I get an object of this type:
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "3"
},
{
"action_type": "like",
"value": "33"
},
{
"action_type": "link_click",
"value": "1531"
},
{
"action_type": "mobile_app_install",
"value": "1049"
}
],
"spend": "8621.03",
"date_start": "2017-10-28",
"date_stop": "2017-11-26"
}
]
If I want it to fetch only the actions where action type is "mobile_app_install", how can I further filter my query?
There is possible to filter that on Facebook side just call it like that:
/act_<yourAdAccount>/insights
?level=campaign
&fields=actions,spend
&time_increment=all_days
&time_range={'since':'2017-07-07','until':'2017-12-12'}
&filtering=[{field: "action_type",operator:"IN", value: ['mobile_app_install']}]
&use_account_attribution_setting=true
I have gone through the documentation as well as the adsinsights.py file on github but I cannot find a way to limit the number of action_types returned. You will simply have to do the filtering after you have retrieved the data from the api.
https://developers.facebook.com/docs/marketing-api/insights/parameters
https://github.com/facebook/facebook-python-ads-sdk/blob/master/facebookads/adobjects/adsinsights.py

Get comments from facebook ads (marketing)

After I make an ads for my post on facebook ads manager.
Facebook Ads Manager show me how many comment belong to this ads. This is very important for me to verify the effective of my campaign.
In programing aspect: Is there's any way to count number belong to my ads like Facebook Ads Manager (I describe above). I have used both Java Facebook Ads SDK (Ads Insight module from https://github.com/facebook/facebook-java-ads-sdk) and Graph Explorer Tool, they both return "comment" field or "like" field not existed
Please help!
You can't get comments nor reactions from Marketing Insights directly.
I stand corrected. If you have access to an ad_account insights, then you can use Marketing API to get a post's comments directly. Thanks #lamxung55
Let's say you have and ad_id of 123000000
If you have a token with ads_management or ads_read permission, you can make a request to the Marketing API such as
/123000000?fields=creative.fields(effective_object_story_id),insights.fields(actions)
This will give you the effective_object_story_id which is the object_id of the post ({page_id}_{post_id}), and its insights including its actions broken down by action type. For example:
{
"creative": {
"effective_object_story_id": "456000000_789000000",
"id": "123000000"
},
"insights": {
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "12"
},
{
"action_type": "like",
"value": "2"
},
{
"action_type": "post",
"value": "3"
},
{
"action_type": "post_reaction",
"value": "29"
},
{
"action_type": "video_view",
"value": "558"
},
{
"action_type": "page_engagement",
"value": "604"
},
{
"action_type": "post_engagement",
"value": "602"
}
],
"date_start": "2017-08-14",
"date_stop": "2017-08-20"
}
],
"paging": {
"cursors": {
"before": "xxx",
"after": "xxx"
}
}
}
}
The effective_object_story_id (so, post_id) is 456000000_789000000.
You can then query the comments edge of the post adding summary=true as a parameter. This endpoint is public for common posts (however, it won't work for non public posts)
/456000000_789000000/comments?summary=true
Which will respond with an object like
{
"data": [
<LOTS OF COMMENTS HERE>
],
"paging": {
<PAGING LINKS>
},
"summary": {
"order": "chronological",
"total_count": 50,
"can_comment": true
}
}
This means the post has had 50 comments, of which 12 were made through a paid action.
We can simply use this syntax to get adset comment: ...adset_id/insights?fields=actions. Another ads stuffs are the same

Combining multiple facebook page reviews feeds in one call

How is it possible that I can add another access token to this call that references the second id I would like to retrieve reviews from.
In all other instances like posts, photos etc this would work but because you are required to have a page access token to retrieve the data for reviews I'm not sure how to construct the url to make the call. Is it possible?
https://graph.facebook.com/ratings?ids=slickremix,reformavi&field=rating&limit=5&access_token=EAAP9hArvboQBAN5...
That call returns something like this, as you can see the second id reformavi is not returning data.
{
"slickremix": {
"data": [
{
"created_time": "2016-10-13T09:22:02+0000",
"reviewer": {
"name": "Jens Kranen",
"id": "10211267740634296"
},
"rating": 5,
"review_text": "Fantastic customer support. Very quick response. Spencer could identify the problem within minutes and gave great advice.\nThank you"
},
{
"created_time": "2016-10-07T14:22:19+0000",
"reviewer": {
"name": "Marc McHale",
"id": "10157614348555341"
}
"rating": 5,
"review_text": "I purchased the Facebook Reviews plugin for a client website and both my client and I are very happy with the appearance and functionality! Plus, the customer service was outstanding!"
}
],
"paging": {
"cursors": {
"before": "MTM4MjkwMTM4ODoxMTg3OTA3NTE1MjU4ODQZD",
"after": "MTI1MTQ3Njk2NToxMTg3OTA3NTE1MjU4ODQZD"
},
"next": "https://graph.facebook.com/v2.7/118790751525884/ratings?access_token=EAAP9hArvboQBAN5HpnbA5m87qC7poAAqB0YS47zxBCBmCfVRcqCC7zX1XDNCv6cSe3KFnMtPVysUms0MuXLxWfv8D9McMwzvD2HWWd0IO6FOZC6ogvcta8FWZBR0vUA9HCZAdqdB53fyUB26XLb76ORLspiPg3Hzb4Pn5RTjwZDZD&pretty=1&limit=5&after=MTI1MTQ3Njk2NToxMTg3OTA3NTE1MjU4ODQZD"
}
},
"reformavi": {
"data": [
]
}
}

PayPal REST API: how to do an immediate payment and without asking for shipping address

I'm trying to use PayPal REST API instead of PayPal Classic API but it seems that the REST API is lacking two features that the Classic API has:
immediate payment: when the user goes to PayPal page show him a "Pay now" button instead of a "Continue" button and "You’re almost done. You will confirm your payment on ..." phrase.
no shipping address: avoid asking the user to confirm his shipping address while on PayPal page (in Classic API is done with NOSHIPPING=1 parameter, if I remember well)
So my question is: is it possibile do perform an immediate payment without asking for shipping address using REST API? Do I have to go back to Classic API?
I provide here a little more informations about how I'm using the PayPal REST API.
I'm using the PayPal REST Java SDK.
This is a sample request:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "5",
"details": {
"subtotal": "5"
}
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"quantity": "1",
"name": "Item 1",
"price": "5",
"currency": "USD"
}
]
}
}
],
"redirect_urls": {
"return_url": "http://XXX/handlePayment.jsp?guid\u003dXXX",
"cancel_url": "http://XXX/cancelPayment.jsp?guid\u003dXXX"
}
}
And its response:
{
"id": "XXX",
"create_time": "2014-06-29T08:52:55Z",
"update_time": "2014-06-29T08:52:55Z",
"state": "created",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
"shipping_address": {}
}
},
"transactions": [
{
"amount": {
"total": "5.00",
"currency": "USD",
"details": {
"subtotal": "5.00"
}
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"name": "Item 1",
"price": "5.00",
"currency": "USD",
"quantity": "1"
}
]
}
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=XXX",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX/execute",
"rel": "execute",
"method": "POST"
}
]
}
While delving through the REST API I came across this
I believe this means you don't have to go about creating any "Profiles" as such, and can just pass them along with the payment call...
Further explanation as requested :)
Below is an example of passing PayPal experience parameters along with a particular payment call using the Client-side JS method for Express checkout.
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
},
experience: {
input_fields: {
no_shipping: 1
}
}
});
},
Hope that makes enough sense to you guys! :)
Unfortunately, the REST API is still a long ways behind the Classic API with features it provides. These features you mentioned are things I've seen come up quite a bit, and to my knowledge they are not yet available with the REST services.
I personally have stuck with Classic as they provide everything and I really see no advantage to using REST myself. If you happen to be working with PHP (which I always do) you may be interested in my class library for PayPal. It makes all of the Classic API calls very quick and easy for you, and it's available on Packagist so you can use with Composer easily.
The REST API now supports no-shipping with the Payment Experience APIs.
You need to create a web experience profile and supply no_shipping as an input field. Then use the profile ID when creating the payment.
The profile ID doesn't need to be recreated every time.
appreciate that this post hasn't had any activity for a while but...
i hit on the exact same problem and used this post as a start point for my own question:
paypal api: take immediate payment without a shipping address
it's taken a bit of trial and error but i you can create a one off web profile with 'no_shipping' set to 1, store the id that it creates and then pass that in with future payments that don't require a shipping address.
still haven't figured out how to get rid of the 'You're almost done. You will confirm your payment on xxx.' but my payment process is a far better place than it was!
hope this helps someone out there as this no shipping issue is one that a lot of people appear to be hitting with the paypal api...
I tried using the experience section of the API and apart from still not being able to force a locale code have been able to disable shipping and go straight to billing:
payment: {
transactions: [{
invoice_number: document.getElementById("ReqTxt").value,
amount: {
total: document.getElementById("InvoiceAmt").innerText,
currency: document.getElementById("Currency").innerText
}
}]
},
experience: {
input_fields: {
no_shipping: 1
},
flow_config: {
landing_page_type:'billing'
}
}
you can also see this page. It is possible to set the user action in the flow_config section too
For 'Pay Now' instead of 'Continue' on Paypal I use a special param in approval url:
$approvalUrl = $payment->getApprovalLink().'&useraction=commit';
Result:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=TOKEN&useraction=commit

Access social readers' posts in a facebook App

How can a facebook app, have access to a social reader's post in the feed? For example, I want to have access to Washington Post's social reader post (when someone else reads an article there and it gets shown up in my news feed) from an app that I am writing. Is it possible to do so, using FQL?
It's easily available in the Graph API (i'll check if it's in FQL)
Basically, either way you'll need to request the user_actions.reads permission from your users. (NB: not user_actions:reads which would be for an app whose namespace is 'reads', for news, music and video apps using the build-in actions there's a special scope)
Then, for the Graph API, just make a call to /USER_ID/news.reads - the response includes the recently read articles from all apps using the built-in 'read' action, example response for my account below:
{
"data": [
{
"id": "REMOVED_ID",
"from": {
"id": "REMOVED_MY_USER_ID",
"name": "REMOVED_MY_NAME"
},
"start_time": "2012-05-10T00:05:10+0000",
"end_time": "2012-05-10T00:05:10+0000",
"publish_time": "2012-05-10T00:05:10+0000",
"application": {
"id": "235586169789578",
"name": "The Independent"
},
"data": {
"article": {
"id": "10150697347986736",
"url": "http://www.independent.co.uk/life-style/food-and-drink/features/the-10-best-scotch-whiskies-1488408.html",
"type": "article",
"title": "The 10 Best Scotch Whiskies"
}
},
"likes": {
"count": 0
},
"comments": {
"count": 0
}
},
.... //more articles