Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook conversion event callback

I cant find in the documentation if there is any callback functionality in the conversion tracking (https://developers.facebook.com/docs/ads-for-websites/tag-api)

In order to track an event you just need to call:

window._fbq = window._fbq || []; window._fbq.push(['track', 'FBCONVERSIONCODE', {'value':'0.00','currency':'USD'}]); 

That is very similar to google analytics conversion code, only though they allow you to call a function when the ajax call finish:

ga('send', 'pageview', {   'page': '/my-new-page',   'hitCallback': function() {     alert('analytics.js done sending data');   } }); 

Is there a way to achieve the same functionality with Facebook API?

like image 253
DomingoSL Avatar asked Apr 07 '15 08:04

DomingoSL


People also ask

What is a conversion event on Facebook?

These conversion events or mobile type events indicate to Facebook the result that you are trying to achieve with the campaign. ℹ️ Note: in order to use either standard events and custom conversion events, you need to have these events implemented as part of your Meta Pixel or mobile app SDK setup.

How do I track a Facebook ad conversion?

There are two main ways to track purchases/conversions from Facebook ads; using the Facebook Pixel and adding Google's UTM tracking code to the destination URLs of the ads for Google Analytics (GA).

How does Facebook track a pixel event on button click?

Navigate to the store where you have set up Facebook Pixel and CTA buttons, then click on Facebook Pixel Helper icon, you can see the tracking of each button. Second way is through Events Manager Diagnostics, click Diagnostics tap to look for further information about your Facebook Pixel.


1 Answers

As of today, Facebook still does not support it. However, since I had this issue due to immediate redirect, I used the following solution:

basically I set on localStorage the variable I needed to track =>

 window.localStorage.setItem('documentTitle', document.title); 

then I did the redirect, and on the targeted page I used the following to properly track fb event

if (typeof(fbq) !== 'undefined' && window.localStorage.getItem('documentTitle')) {     fbq('track', 'Lead', {content_name: window.localStorage.getItem('documentTitle')});     window.localStorage.removeItem('documentTitle');} 

Hope this helps someone ;)

PS: this will work only if the redirected page is on the same host of the initial page, since localStorage is unique per: protocol://host:port

like image 182
stefano salvucci Avatar answered Sep 21 '22 23:09

stefano salvucci