Facebook pixel events call from server - facebook

I have absolutelly the same question as dan here - Facebook conversion pixel with "server to server" option . There was written, that there was no way, but it was 2013, so I hope something changed.
So, is there any way to call facebook pixel events (e.g. CompleteRegistration) from server side now?
I can describe situation in more details. Imagine, that user visits our site, where fb pixel tracks 'PageView' of course. When user passes form and sends his phone number, we call 'Lead' event. But then we need to track one more event, when our manager successfully confirmes this user! Of course, it happens on other computer and so on, so there is no idea, how to "connect" to base user.
I've seen a lot of documentation departments like this, but I can't fully understand even if it's possible or not.
Logically, we need to generate specific id for user (or it can be phone number really), when 'Lead' event is called. Then, we should use this id to 'CompleteRegistration' for that user. But I can't understand, how to do it technically.
It would be gratefull, if somebody could explain it.
P.S. As I understand, it is fully available in API for mobile apps. Is it ok idea to use it for our situation, if there is no other solution?

Use Offline Conversions to record events that happen after a user has left your website. Logging these conversions, technically, is very easy. Setting everything up takes a little effort
tldr; check the code below
Follow setup steps in the FB docs (Setup steps 1-5) which are:
Setup facebook Business Manager account
Add a new app to Business Manager account
Create an Ad account, if you don't already have one
Create a System User for the ad account
After the setup, follow Upload Event Data steps on the same page, steps 1-3 to create an offline event set and associate it with your ad. These can be carried out in the Graph API Explorer by following the links in the examples. These can be done programmatically, but is out of the scope of making the event calls from the server for one campaign.
Once you have created the event set, then you can upload your CompleteRegistration events!
You will need to make a multipart form data request to FB, the data key will be an array of your conversion events. As #Cbroe mentioned, you must hash your match keys (the data you have available about your user to match them with a FB user) before sending to FB. The more match keys you are able to provide, the better chance at matching your user. So if you can get their email and phone at the same time, you're much more likely to match your user.
Here's an example of the call to FB using node.js:
var request = require('request')
// The access token you generated for your system user
var access_token = 'your_access_token'
// The ID of the conversion set you created
var conversionId = 'your_conversion_set_id'
var options = {
url: 'https://graph.facebook.com/v2.12/' + conversionId + '/events',
formData: {
access_token: access_token,
upload_tag: 'registrations', //optional
data: [{
match_keys: {
"phone": ["<HASH>", "<HASH>"]
},
currency: "USD",
event_name: "CompleteRegistration",
event_time: 1456870902,
custom_data: { // optional
event_source: "manager approved"
},
}]
}
}
request(options, function(err, result) {
// error handle and check for success
})
Offline Conversion Docs

Facebook has now a Server-Side API: https://developers.facebook.com/docs/marketing-api/server-side-api/get-started
Implementing this is similar to implementing the offline events outlined in the accepted answer.
Keep in mind that it will always be cumbersome to track and connect events from the browser and from your server. You need to share a unique user id between the browser and server, so that Facebook (or any other analytics provider) will know that the event belongs to the same user.
Tools like mixpanel.com and amplitude.com may be more tailored to your needs, but will get very expensive once you move out of the free tier (100+ EUR at mixpanel, 1000+ EUR at Amplitude, monthly). Those tools are tailored towards company success, whereas Facebook is tailored towards selling and measuring Facebook ads.

Related

Facebook offline conversions without customer data associating with ad reporting

I have ads on Facebook driving traffic to our site.
I set this on land
fbq('init', 'my_id', {
external_id: "d1fd01cb777cdcdbf5161db889bf841e"
})
and later if we have an actual purchase I send an offline purchase event using extern_id to match on.
[{
:match_keys => {
:extern_id => "d1fd01cb777cdcdbf5161db889bf841e"
},
:event_time => 1579464000,
:event_name => "Purchase",
:value => 5.0,
:currency => "USD",
:order_id => "8431715",
:custom_data => {
:event_source => "affiliate"
}
}]
however I am not seeing the offline events associated with the ads.
Has anyone else had this issue and have they found a solution??
Davinj, if I understood you correctly, you try to send pixel events giving your extren_id and then matching it back to customers who made a purchase as offline conversions? I see several issue with this:
You have your extern_id in pixel's init code instead of event itself. Like standard conversions or at least page view. Also you call it extrn[al]_id which is inconsistent with extern_id.
I doubt that such scenario would work in the first place as offline conversions do not usually play well with pixel and might not be able to have the parameter from pixel as a match key. Even if the do, which you might find via testing, you'll still have to send other match keys to identify the FB user like email, phone number, etc. Here are docs explicitly recommending that: https://developers.facebook.com/docs/marketing-api/offline-conversions#extern-id
When you have a consistent pixel setup and can see proper events with corresponding parameters, you'll be able to see if you idea is viable.
Generally FB explicitly says that extern_id is a user identifier in you system and probably has to be different for every customer. It can be send as a lonely match key only after you already used it once with other match cases to identify an FB user. Otherwise FB just skips such events and you'll see nothing.
Hope it helps.
#Davinj,
There is another way to send offline events via server-side-api to your pixel's dataset:
https://developers.facebook.com/docs/marketing-api/server-side-api
I think these should match up as they show in the same pixel when using event manager.
I had the same assumptions as you but I think their offline conversions is for people who didn't land on your site before converting. Maybe just saw your advert or something.

Google Calendar REST API does not return title and other event fields

Google calendar REST API GET method (https://developers.google.com/calendar/v3/reference/events/get) should return this structure (https://developers.google.com/calendar/v3/reference/events#resource), unless I'm missing something.
I need to get event title and description to use in my application. I 'm getting below response instead.
I've tried to change event visibility (public/private) and availability (free/busy). Actually, API does not show events with Free availability, for which I don't have solution either.
Here is event edit screen screenshot:
https://www.screencast.com/t/X8bRS8kJDT
{
"kind":"calendar#event",
"etag":"\"3145149995624000\"",
"id":"5fnlvcl2msab46p8roqbahhb6g",
"status":"confirmed",
"htmlLink":"https://www.google.com/calendar/event?eid=NWZubHZjbDJtc2FiNDZwOHJvcWJhaGhiNmcgZWQtYWRtaW4uY29tXzMwOHNycjdzdjdiM28xazRpdjZ2cm9mb3Y0QGc",
"updated":"2019-11-01T02:23:17.812Z",
"start":{
"dateTime":"2019-11-11T09:30:00+11:00"
},
"end":{
"dateTime":"2019-11-11T10:00:00+11:00"
},
"visibility":"private",
"iCalUID":"5fnlvcl2msab46p8roqbahhb6g#google.com"
}
Are there other methods to get calendar events details with REST API, including ones with free availability?
Thanks.
04/02/2020:
I actually made it work for "ordinary" Google account - add project, add API, add service account and allocate service account email to the calendar. But I still not sure how to change access level for G Suite account. It allows only to see Free/Busy status.
I've changed default access in Admin Console as this article suggests, but it does not help:
https://www.macworld.com/article/2980005/the-mystery-of-the-unsharable-google-apps-calendar.html
You could try specifying the fields you want to retrieve like the image below:
Or you could put a " * " as the image below to retrieve all values:
fields is a standard Query parameter, which specifies what values you want to include in your response. To learn more about it, you can check Here.

After AccountManager..getAuthToken, how to send that token to its provider to authenticate something?

We're writing an app with an Android view and a website. Our app needs to associate some data with Facebook, Google, or Twitter (call them 'FGT'), and then hit the associated service to return true if that data is authenticated. The control flow is...
Android generates some data
User selects an FG or T account
getAuthToken
upload the data+token, via HTTPS POST, to our website
Our website (in Django, not that it matters) sends the Auth Token to FGT
FGT returns true if it likes that token, and false if it doesn't
The goal is preventing an attacker from concocting data and throwing it at our site with curl. And we /don't/ need to upload the data all the way to F, G, or T. We don't need to go all the way to a Hybrid App, where our webservice authenticates itself to F, G, or T, and then uses F, G, or T's API to post, e-mail, or tweet in the user's name.
There's obviously a simple answer for this out there somewhere; hopefully just three URIs, one each for F, G, or T, into which I can insert the Auth Token. That's why I would prefer NOT to download and install the SDK for each of Facebook, Google, and Twitter, and then write tons of service-specific code for each case. That would clutter up the code, and leave me screwed when the client requests Tumblr or MSN.
(A related question: What's the second parameter of getAuthToken()? "ah"? "mail"?)
So, while I continue to read books, source code, and SO posts showing how to do hard things the hard way, can someone tip me off how to do an easy thing the easy way?
The thread "validating Android's authToken on third party server" answered the sub-question "what simple URI to hit to test a token?"
The magic uri, for Google, is: https://accounts.google.com/o/oauth2/tokeninfo?access_token=%token_here%
The next question is How to thump an Access Token out of getAuthToken. The scope there should be the minimum possible to show a user really lives here:
String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";
am.getAuthToken(a, SCOPE, false, this, null);
My this class implements AccountManagerCallback<Bundle> and provides the method run(AccountManagerFuture<Bundle> result). That, per documentation such as "Android AccountManagerFuture getResult gives IOEXcelption when trying to get authorization token", might call startActivity() to challenge the user to authorize this activity, or it might use a token that's already stored in the AccountManager. (And note that implementing a class just to call-back yourself is pernicious, especially if the target method's named merely run(), so do as I say not as I do, kids!)
The resulting token is 52 bytes long, beginning with 'ya29.', so it's _ probably _ an access_token, not 331 characters, which is probably an id_token.
The resulting token is not bound to any specific channel (where "channel" is one unique set of client, server, and scope). So, from a simple curl, I can hit that /tokeninfo URI with it, and get this (scrubbed) JSONic wisdom:
{
"issued_to" : "442575845966-mde4be7eingpb5pntfs839jipsetro6s.apps.googleusercontent.com",
"audience" : "424242424242-mde4ab7defghi5jklmn839opqrstuv6s.apps.googleusercontent.com",
"user_id" : "424242424242424242424",
"scope" : "https://www.googleapis.com/auth/userinfo.profile",
"expires_in" : 2272
}
And so this answer would have formed, for me, the missing link between all the other documentation I was trying to read. Aaand now I need to do it all again for Facebook & Twitter...
There is a simple URL.
Each authtoken is granted against a scope. Each scope allows the authtoken to do certain things. If you try to do something that the scopes permit, that thing will fail or succeed based on the validity of the authtoken.
The simplest scope to request is probably 'email'.
If you go to the Oauth2 Playground at https://developers.google.com/oauthplayground/ you can experiment with scopes and calls to get one that suits you. You'll be able to see the URLs that you then need to replicate in your app.

Retrieving the action-instance-id from Facebook given the URL

tl;dr: No, there isn't a way.
Calling publish_action using the JS SDK is actually pretty straightforward. However (from the little info I gleaned from reading the documentation), there's no way for me to query facebook to have it return the action instance ID for an object that I have already published... is there?
Example:
User A loads the page, and the page sends an FB.api call to /me/news.reads, which returns an action instance ID.
User A reloads the page, and the page again sends an FB.api call to /me/news.reads, but this time, the Graph API returns:
{
error: {
code: 3501,
message: 'blahblahblah... already associated... blah blah'
type: 'OAuthException'
}
}
Pretty standard stuff, and expected, since I turned off the ability to publish the same URL multiple times.
Now then, is there any way for me to retrieve a previously published action instance ID from the Graph API by passing in the URL, or is it up to me to handle the returned action instance ID (from the original publication attempt) and save it to a database? I was hoping I wouldn't have to do that...
No, there is no way to retrieve instances of published actions other than:
Accessing action by id:
http://graph.facebook.com/ACTION_ID
Accessing all instances published by specific user:
http://graph.facebook.com/USER_ID/NAMESPACE:ACTION (NAMESPACE:ACTION may be replaces by the name of one of built-in actions like news.reads, music.listend, etc.
If you want to access details of published actions connected/referencing specific object you'll need to save that data on your end for later usage.

OpenGraph: how can i specify a filter in FB.api?

I have built a Facebook app using OpenGraph that permits the users to write reviews on concerts, so that I've defined a concert_id attribute on which the user can insert a review.
Now I would like to show all the reviews inserted for a certain concert_id but cannot find a way. If I do (in JS)
FB.api('/me/MY_APP:action', { limit: 0}, function(response) {
console.log(response);
});
I get all items. This app has to be consumed by mobile, I think it is bad to get all items and, then, filtering only the concert_id i need. What do I have to do to apply a where condition in OpenGraph to a custom action?
As far as I can tell from the API and the Facebook developer pages, it's not possible to filter a call by custom action property using the public Open Graph API.
Two options I can think of:
Option 1:
Implement the category filter by creating custom category objects:
if "review" is a custom action and
GET https://graph.facebook.com/me/[name_space]:review
returns all review actions then
GET https://graph.facebook.com/me/[name_space]:review/scifi_movie
GET https://graph.facebook.com/me/[name_space]:review/action_movie
return actions specific to movie type, where scifi_movie and action_movie are custom objects. You would need to create one object type for each category.
Option 2:
Implement a custom action for each category, e.g.
review_scifi_movie
review_action_movie
These are not particularly elegant solutions but perhaps useful as a hack if nothing else works and you really don't want to do filtering on client side.
The Facebook API will not return individual published objects for a particular action, but that's not your only problem. By the look of it, you're trying to bring in ALL the reviews given for a concert, right? (Meaning those by other users too).
The "/me/" part of the Facebook API call will only return those published actions made by the user that is currently logged in. That won't work for you, as you want those of all your users
The only suggestion I can give is to create a simple web service, where you store all the reviews given for the various concerts. Use this service to pull in reviews given for a particular concert. (I use a similar methodology for reviews in an app of my own).
I dont understand javascript or opengraph..
But when I required in JAVA to fetch reviews made by any user I have used FQL for that and It retrived me all the reviews and FQL also used to fetch all the tables related to Facebook.
I don't think that you can pull that off with the JS SDK.
You can do that in your server though, and since this is a mobile app (or has a mobile version) then that's another good reason to remove this from the client responsibility.
In the server side you can ask facebook for the published actions as you posted, filter them and then return the response.
Another thing that you can do is to save each published action in your db (on each action post you should get an id back from facebook, just persist that) and then you can easily filter the published actions according to what ever criteria you want/need (since you are no longer restricted by the facebook api).
The open graph thing is still pretty new and not tat mature, for example you can't use FQL with it, something that could have been handy for your case.
Regardless though I think that a server solution is best for calculations when mobile is concerned.
i don't know exactly but try this
if (session.authResponse) {
FB.api('/me', {
fields: 'name, picture' // here mention your fields
},
function(response) {
if (!response.error) {
//here response value
});