Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davekuhar/7103cddd4ebfec3cfea8c150a53ee005 to your computer and use it in GitHub Desktop.
Save davekuhar/7103cddd4ebfec3cfea8c150a53ee005 to your computer and use it in GitHub Desktop.

Please follow these instructions to add a global Facebook pixel to URLs on your subdomain, and to send events to Facebook. These modifications will allow all advertisers in the Stanford Univ. organization to have meaningful conversion events based on the stanford.edu domain to leverage as conversion events with Facebook ad sets that are in a conversion objective campaign.

Please note that custom events, custom conversions and custom audiences based on your current pixel(s) will survive these modifications. Once these modifications are made for most advertisers, after roughly a week’s data has collected against the global pixel, we’ll communicate planned changes to be made at a specific date / time to the AEM events list for stanford.edu. At that time we will be asking each advertiser transition to using standard events associated with the global pixel as their ad set conversion events. The global pixel will be shared with each advertiser’s Facebook business manager account so related events can be used as conversion events. However, permissions will be restricted and will not allow advertisers to use the global pixel to configure custom audiences.

Please note there is no consideration given to these modification instructions for any web regulation or cookie consent method (i.e. CCPA, GDPR, etc...).

Instructions

To eliminate the unexpected behavior caused by initializing multiple pixels, we are asking you to modify your existing trackCustom based events to leverage trackSingleCustom (and track to trackSingle) specifying your non-global pixel ID. This will ensure those custom events are only sent to that pixel (vs the default behavior which broadcasts the event to all initialized pixels).

We’ll also ask that you add a separate “sister” instance of a given custom event as a standard event using trackSingle and specifying the global pixel ID (1199096620574484). An inventory of possible standard events, and descriptions of related user actions so you can select the most appropriate standard event for your scenario, can be found at https://developers.facebook.com/docs/facebook-pixel/reference. When our requests are executed, we’ll get a full inventory of standard events firing to the global pixel which can later be assigned to the AEM tool for stanford.edu.

Two Action Items:

  1. Per the example below, add a second fbq(‘init’) for the global pixel. NOTE: If using GTM, remove the <noscript> tag as GTM ignores it

    <!-- Facebook Pixel Code -->
    <script>
      !function(f,b,e,v,n,t,s)
      {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
      n.callMethod.apply(n,arguments):n.queue.push(arguments)};
      if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
      n.queue=[];t=b.createElement(e);t.async=!0;
      t.src=v;s=b.getElementsByTagName(e)[0];
      s.parentNode.insertBefore(t,s)}(window, document,'script',
      'https://connect.facebook.net/en_US/fbevents.js');
      fbq('init', '<YOUR_PIXEL_ID>'); // Your Specific Pixel
      fbq('init', '1199096620574484'); // “stanford.edu Global Pixel - May 2021" (global pixel)
      fbq('track', 'PageView'); // Add both init lines *before* this PageView track line so a PageView is recorded for *all* pixels.
    </script>
    <noscript>
      // If using GTM, remove this noscript tag as GTM ignores it.
      <img
        height="1"
        width="1"
        style="display:none"
        src="https://www.facebook.com/tr?id=<YOUR_PIXEL_ID>&ev=PageView&noscript=1"
      />
      <img
        height="1"
        width="1"
        style="display:none"
        src="https://www.facebook.com/tr?id=1199096620574484&ev=PageView&noscript=1"
      />
    </noscript>
    <!-- End Facebook Pixel Code -->
  2. For each event. Using code inserted after the above Facebook tag library (fbevents.js) + two fbq('init') lines (pixels must be initialized before events can fire), when a user has executed the action related to a respective event, add code to fire events per the following example.

    Template

    From...

    <script>
      fbq('trackCustom', '<YOUR_CUSTOM_EVENT_NAME>', {
        //...event details
      });
    </script>

    To...

    <script>
      fbq('trackSingleCustom', '<ADVERTISER_PIXEL_ID>', '<YOUR_CUSTOM_EVENT_NAME>', {
        //...event details
      }); // Modify existing trackCustom that sends a custom event to instead reference trackSingleCustom specifying the non-global pixel ID.
      fbq('trackSingle', '1199096620574484', '<STANDARD_EVENT_NAME>', {
        content_name: '<YOUR_CUSTOM_EVENT_NAME>',
      }); // Add a separate instance of the above custom event as a **standard** event using trackSingle and specify the “stanford.edu Global Pixel - May 2021" ID.  You can add a content_name value describing the related custom event.
    </script>

    Specific Example

    From...

    <script>
      fbq('trackCustom', 'Exed Ed Silo - Brochure', {
        content_name: 'LEAD',
      });
    </script>

    To...

    <script>
      fbq('trackSingleCustom', '550277008866906', 'Exed Ed Silo - Brochure', {
        content_name: 'LEAD',
      });
      fbq('trackSingle', '1199096620574484', 'Lead', {
        content_name: 'Exed Ed Silo - Brochure',
      });
    </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment