Firing the Facebook Conversion Pixel

后端 未结 5 2024
广开言路
广开言路 2021-01-31 20:32

I\'m still pretty new to Javascript, but I was wondering what would be the best way to fire the Facebook conversion pixel (below) without actually loading a \"confirmation\"/\"T

5条回答
  •  清歌不尽
    2021-01-31 21:09

    I was having similar kind of issue and I would like to run multiple adds to track pixels codes and some reason I was not able to track. What I did is that, in the current page I have added pixel code in footer and javascript function to call when my ajax button get submitted.

    First refer to Facebook documentation page

    https://developers.facebook.com/docs/ads-for-websites/conversion-pixel-code-migration#multi-conv-events

    How to track Multiple Conversion Events

    After the base code snippet is installed, you can track multiple conversions within the same web page by making multiple _fbq.push('track') calls for each conversion pixel ids. For example:

    _fbq.push(['track','',{'value':'10.00','currency':'USD'}]);
    _fbq.push(['track','']);
    

    How to track In-Page Events

    After the base code snippet is installed, you can track in-page actions, such as clicks on a button, by making a _fbq.push('track') call for the conversion pixel through registering different event handlers on an HTML DOM element. For example:

    function trackConversionEvent(val, cny) {
      var cd = {};
      cd.value = val;
      cd.currency = cny;
     _fbq.push(['track', '', cd]);
     }
     

    Also, add the facebook pixel tracking code chrome addon and refer the facebook pixel helper page: https://developers.facebook.com/docs/ads-for-websites/pixel-troubleshooting

    See my below solution/answer

    Facebook tracking code in the current page (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', 'yourid', {'value':'1.00','currency':'USD'}]);

      
      
    

    And the javascript code to call when ajax form submit or button click

     
    

    and the call the function when ajax called

    jQuery(form).ajaxSubmit({
    
       type:"POST",
    
       data: $(form).serialize(),
    
       url:"process.php",
    
        success: function() {
        **trackConversionEvent**('1.00','USD');
       }
       ......
    

提交回复
热议问题