Facebook Tracking of In-Page Events with Conversion Pixel Code -


full disclosure - i'm not programmer, i'm 1 in organisation might able working. can following please?

i'm trying use facebook's conversion pixel code track button clicks on our site. facebook's developer docs give following instructions tracking in-page events:

after base code snippet installed, can track in-page actions, such clicks on button, making _fbq.push('track') call conversion pixel through registering different event handlers on html dom element. example:

function trackconversionevent(val, cny) {   var cd = {};   cd.value = val;   cd.currency = cny;   _fbq.push(['track', '<pixel_id>', cd]); } <button onclick="trackconversionevent('10.00','usd');" / 

the problem i'm facing it's not clear me facebook means "the base code snippet". initial assumption it's conversion pixel code give install in head section of page, i.e.

<!-- facebook conversion code --> <script>(function() {   var _fbq = window._fbq || (window._fbq = []);   if (!_fbq.loaded) {     var fbds = document.createelement('script');     fbds.async = true;     fbds.src = '//connect.facebook.net/en_us/fbds.js';     var s = document.getelementsbytagname('script')[0];     s.parentnode.insertbefore(fbds, s);     _fbq.loaded = true;   } })(); window._fbq = window._fbq || []; window._fbq.push(['track', '<pixel_id>', {'value':'0.00','currency':'usd'}]); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=<pixel_id>&amp;cd[value]=0.00&amp;cd[currency]=usd&amp;noscript=1" /></noscript> 

however, if install above on our page loads/fires conversion pixel code each time page loads rather on button click (presumably because it's typically used on thank you/confirmation page). can shed light on me? believe understand position onclick code associate button click i'm struggling understand need position trackconversionevent code , base code snippet is. through testing, know removing following lines larger code snippet stops pixel loading:

window._fbq = window._fbq || []; window._fbq.push(['track', '<pixel_id>', {'value':'0.00','currency':'usd'}]); 

but i'm not sure if that's need do. example, need replace 2 lines trackconversionevent code pixel doesn't fire when page loads onclick code functions instead when button clicked?

many in advance pointers or suggestions.

this should work, i.ve tested on blog based on wp.

<!-- facebook conversion code --> <script>(function() {   var _fbq = window._fbq || (window._fbq = []);   if (!_fbq.loaded) {     var fbds = document.createelement('script');     fbds.async = true;     fbds.src = '//connect.facebook.net/en_us/fbds.js';     var s = document.getelementsbytagname('script')[0];     s.parentnode.insertbefore(fbds, s);     _fbq.loaded = true;   }  })();  window._fbq = window._fbq || [];  </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=<pixel_id>&amp;cd[value]=0.00&amp;cd[currency]=usd&amp;noscript=1" /></noscript>       <!-- end of facebook conversion code --> 

this event handler bind button, link or dom element::

function trackconversionevent(val, cny) {   var cd = {};   cd.value = val;   cd.currency = cny;   _fbq.push(['track', '<pixel_id>', cd]); }  <button onclick="trackconversionevent('10.00','usd');"  

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -