How to use script and install FB pixel on website

Created a configuration field to update the meta pixel id .

Deployed the pixel base code to which contain a pixel id for the use of conversion tracking.

define(

  ‘JJ.FBPixelIntegration.FBPixelIntegration’

, [

  ]

function (

  )

{

  ‘use strict’;

  return {

    mountToApp: function mountToApp (container)

    {

      var PDP = container.getComponent(“PDP”);

      var plp = container.getComponent(“PLP”);

      var self = this;

      var Config = container.Configuration

      var Enable = true;

      // Enable = Config.FBPixelIntegration.enable;

    //  console.log(‘Config’, Config)

      var GAU_ID = Config.FBPixelIntegration.gauid || ‘UA-55727250-1’;

      var GTM_ID = Config.FBPixelIntegration.gtmid || ‘GTM-WB3CJG6’;

      var FBPixelid = Config.FBPixelIntegration.fbpixelid;

      var scriptHead = ;

      if (Enable && FBPixelid) {

        scriptHead += ‘<!– Facebook Pixel Code –>’

        scriptHead += ” <script>”

        scriptHead += “! function(f, b, e, v, n, t, s) {“

        scriptHead += ” if (f.fbq) return;”

        scriptHead += ” n = f.fbq = function() {“

        scriptHead += ” n.callMethod ?”

        scriptHead += ” n.callMethod.apply(n, arguments) : n.queue.push(arguments)”

        scriptHead += “};”

        scriptHead += “if (!f._fbq) f._fbq = n;”

        scriptHead += “n.push = n;”

        scriptHead += “n.loaded = !0;”

        scriptHead += “n.version = ‘2.0’;”

        scriptHead += “n.queue = [];”

        scriptHead += “t = b.createElement(e);”

        scriptHead += “t.async = !0;”

        scriptHead += “t.src = v;”

        scriptHead += “s = b.getElementsByTagName(e)[0];”

        scriptHead += ” s.parentNode.insertBefore(t, s)”

        scriptHead += “}(window, document, ‘script’,”

        scriptHead += “‘https://connect.facebook.net/en_US/fbevents.js’);”

        scriptHead += “fbq(‘init’, ‘” + FBPixelid + “‘);”

        scriptHead += “fbq(‘track’, ‘PageView’);”

        scriptHead += ‘</script>’

        scriptHead += ‘<noscript>’

        scriptHead += ‘<img height=”1″ width=”1″ style=”display:none” src=”https://www.facebook.com/tr?id=’ + FBPixelid + ‘&ev=PageView&noscript=1″ />’

        scriptHead += ‘</noscript>’

      }

      if (scriptHead)

      jQuery(‘head’).append(jQuery(scriptHead));

    }

  };

});

To verify the installation, load a page that has the Pixel. This should call fbq(‘track’, ‘PageView’), which will be tracked as a PageView event in the Events Manage and Install the Meta Pixel Helper extension to validate the installation.

Leave a comment

Your email address will not be published. Required fields are marked *