Facebook Instant Articles: how to use the Google Analytics gtag.js tracking code

In a previous post I described how to use the Google Analytics analytics.js tracking code with Facebook Instant Articles. However, Google Analytics recently updated its tracking code to the Global Site Tag or gtag.js format.

gtag.js:

Fortunately, as with analytics.js you can also use the gtag.js tracking code with Instant Articles by simply enclosing it in the necessary figure and iframe tags and inserting it in the body (not in the header or footer) of an Instant Article.

Original gtag.js tracking code:

Simply replace GA_TRACKING_ID with your own analytics ID and the above example will already work. However, you will not be able to distinguish traffic from Instant Articles from all other traffic and you will also not be able to identify the specific Instant Articles receiving traffic. To be able to do that you have to use a modified gtag.js tracking code.

Modified gtag.js tracking code:

The above tracking code populates the Page Title field (not specified by default) with the corresponding post title and the prefix "Instant Articles: " to identify the post and its source when displayed on the Google Analytics dashboard.

Labels: , , ,

« Older PostBack to TopNewer Post »