Facebook Instant Articles: use Google Tag Manager to integrate Google Analytics

I am currently using Google Tag Manager (GTM) to integrate Google Analytics with Facebook Instant Articles using the built-in Universal Analytics tag. Below is the code that I use. Note that in Instant Articles there is no need for the <noscript> component.

Assuming that you have already installed the Universal Analytics tag in Google Tag Manager, just replace GTM-XXXX in the above example with your own container ID and insert it in the body (not the header or footer) of your Instant Articles and it will already work. However, for it to be really useful you need to configure three fields: campaignMedium, campaignSource, and title. Otherwise, you will not be able to distinguish traffic coming Instant Articles from all other traffic.

The campaignMedium and campaignSource fields are easy to set because you just need to select them and assign the corresponding fixed values, for example, "Instant Articles" for campaignMedium and "Facebook" for campaignSource.

variable configuration

The title field, however, needs additional configuration to display a dynamic value that makes use of the "ia_document.title" variable in Instant Articles.

How to create a custom title variable for Universal Analytics

  1. Go to the Variables panel and create a new user-defined variable.
  2. In Variable Configuration select Custom JavaScript.
  3. In the Custom JavaScript editing window create the following script:
  4. Save the script and name it "Document Title".
  5. You can now use the variable {{Document Title}} to set a dynamic value for the title field, for example, "Instant Articles - {{Document Title}}".

Filtering traffic from the web and Instant Articles

You don't have to create a separate container for Instant Articles when using Google Tag Manager. You can simply install two instances of the Universal Analytics tag and then create separate triggers for web traffic and Instant Articles.

For this to work, you will first have to create a custom variable to make use of the "ia_document.referrer" variable in Instant Articles, as follows.

  1. Go to the Variables panel and create a new user-defined variable.
  2. In Variable Configuration select Custom JavaScript.
  3. In the Custom JavaScript editing window create the following script:
  4. Save the script and name it "Document Referrer"

You can now use the custom variable "Document Referrer" to create a trigger that fires when the referrer equals "ia.facebook.com".

For Instant Articles:
Trigger: Page View > Some Page Views
Condition: Document Referrer > equals > ia.facebook.com
IA trigger
For web traffic:
Trigger: Page View > Some Page Views
Condition: Document Referrer > does not equal > ia.facebook.com
web trigger

For Instant Articles the referrer is constant and is always set to "ia.facebook.com".

Labels: , , ,

« Older PostBack to TopNewer Post »