Below is the Tag Manager code for pbs.org. It should not be used on any other domains or any station sites. 

Google Tag Manager Container code for PBS.org

Paste this code as high in the <head> of the page as possible:

# -----------------------PBS Google Tag Manager container----------------------------


<!-- Google Tag Manager -->

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','GTMDataLayer','GTM-TWTDGH');</script>
<!-- End Google Tag Manager -->

Paste this code immediately after the opening <body> tag:

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TWTDGH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) →

Custom Event Tracking

This is for National Show Producers who want to implement custom event tracking that is different from the default event tracking. 

The following section explains how a producer can implement Custom Google Analytics Event-Tracking on their website. By default the PBS analytics infrastructure automatically handles some critical Event-Tracking so there is no need for producers to build it themselves. 

The following are Google Analytics Events that are sent automatically to a show's Google Analytics property. 

  1. Media Manager video infrastructure handles all Event Tracking of video streaming on producer websites.That system is separate from the on-page analytics tagging (Google Tag Manager) and is instead built in to the video players themselves. This system reports when a stream happens on a producer’s show, what video was streamed, when, where, and for how long.
  2. Clicks that initiate a file download. If the producer has a link on their website that allows a user to download a file (e.g. a PDF), the PBS Google Tag Manager container automatically sends an Event to that show’s Google Analytics “Page-Tracking” property (typically the property ID that ends with -1).
    1. That event will be labeled this way:
    2. Event Category = File Downloads
    3. Event Action = the format of the file that was downloaded (e.g. .txt, .pdf. .csv)
    4. Event Label = the URL of the page the user was on when they clicked the file
  3. Clicks that send the user off the PBS.org domain. If there is a link on a show website that sends the user to a different domain, the PBS Google Tag Manager container automatically sends an Event to the show’s Google Analytics “Page-Tracking” property (typically the property ID that ends with -1)
    1. That event will be labeled this way:
    2. Event Category = Outbound Link Click
    3. Event Action =  the URL of the link the user was sent to
    4. Event Label = the URL of the page the user was on when they clicked the link


If the show producer would like to record a Google Analytics Event for any other type of interaction on their site beyond the above default events they should use the following method. 

Many years ago show producers were able to just send standard Google Analytics events using the default method recommended in the Google Analytics documentation. This is no longer the case. Only the method described below (where Custom Google Analytics Events are sent to the data layer) will work and is supported. 

Details

In early 2016, entire analytics infrastructure for PBS.org was in to Google Tag Manager. All Google Analytics tags will be triggered within the Google Tag Manager, therefore you can no longer rely on the old "Classic" (ga.js) or new "Universal" Google Analytics (analytics.js) Javascript libraries to be loaded on the page. With those libraries not loading, the existing method for sending an event through the "_trackEvent" method (ga.js) or "send" command (analytics.js)

Historical documentation:

ga.js: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
analytics.js: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
Those approaches will no longer work.

New Solution

Instead of sending events through the Google Analytics tracker object, an event can now be sent to the Google Tag Manager Data Layer by sending a dataLayer push.

For example, instead of (analytics.js example):

onclick="ga('send', 'event', 'category', 'action', 'label', value, false);";

You must use:

onclick="dataLayer.push({'event': gaEvent', 'eventCategory': 'category', 'eventAction': 'action', 'eventLabel': 'label', 'eventValue': value, 'eventNI': false});";

Any custom event-tracking you implement on a pbs.org website should use this data layer approach. Other methods will not work.

Example

To see an example of the new dataLayer method in action click on one of the Social Sharing buttons on this page: http://www.pbs.org/wgbh/frontline/film/the-secret-history-of-isis/

Account Information

The Google Tag Manager will automatically send events to the "Page-Tracking" property in a Producer's Google Analytics account. This will usually be the Google Analytics property with the ID that ends in "-1". e.g. UA-123456-1.

In the past it was recommended that you sequester any Google Analytics events in a separate "Event-Tracking" property. In most cases this is the Google Analytics property with the ID that ends in "-2". e.g. UA-123456-2. That is no longer a best practice. By sending events to a producer's page-tracking account this will allow you to analyze that data within the context of the rest of the behavioral data about the site.

Google Tag Manager details

PBS has implemented the Google Tag Manager (GTM) across all webpages on the pbs.org domain.

That GTM container should be implemented across all producer show-site webpages using one of two methods;

  • Legacy -  The "Global Server Side Include": <!--#include virtual="/includes/global-chrome/companion-ssi.html"→
  • Current/Preferred - direct implementation in to the HTML <head> tag of all pages. (see above)

In the GTM container there is a generic Google Analytics event tag that is triggered on the custom event gaEvent, with variables to capture and pass along the category, action, label, value, and non interaction parameters.

Basically the event-tag is listening for a gaEvent to be sent to the dataLayer. When it is sent the tag obtains the relevant data/parameters from the dataLayer (e.g. Event Category, Event Action, Event Label, etc.), checks to see what the URL is for the page, and then sends the event to the respective Google Analytics account for that site.

The gaEvent tag knows which Google Analytics account to send the event to based on a LookUp table that lists the Property ID's (e.g. UA-123456-7) and URL's for each show website.

Why a National Producer cannot include their own GTM container on a page

  • Google says you must make sure the data layer object is named the same: https://developers.google.com/tag-manager/devguide#multiple-containers
  • We have a custom name for our data layer. If that doesn’t match it could cause issues. That is easily resolved by having the producer rename their data layer object to match. 
  • However this means that the two containers must share a data layer. 
  • When they share a data layer there is a risk that if the developer sends an event to the data layer that is named the same as an event we rely on in our container they could trigger an event in our container. 
  • We have been advised by experts that this has happened at other companies. 
  • The only way around this is to coordinate with the developer the names of all the data layer objects we have and will ever use to ensure that we will never trip over each other. 
  • That is not something we are staffed to do. 


  • No labels