Firing the Facebook Conversion Pixel

后端 未结 5 2081
广开言路
广开言路 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:06

    Just move the entire original code into the event of your choice. Then just change 1 part of the code. The thing you will have to do is make the fb_param global instead of local.

    See below at the comment

    $('.button').click(function() {
        window.fb_param = {}; // must be global by adding `window.`
        fb_param.pixel_id = '123456789';
        fb_param.value = '0.00';
        fb_param.currency = 'USD';
        (function(){
            var fpw = document.createElement('script'); fpw.async = true; fpw.src = '//connect.facebook.net/en_US/fp.js';
            var ref = document.getElementsByTagName('script')[0];
            ref.parentNode.insertBefore(fpw, ref);
        })();
    });
    

提交回复
热议问题