-
-
Save danielmcclure/a22b13f92fdaaac2748fe9359222e215 to your computer and use it in GitHub Desktop.
Google Analytics Global Site Tag (gtag.js) for Facebook Instant Articles (Full Snippet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<figure class="op-tracker"> | |
<iframe> | |
<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments)}; | |
gtag('js', new Date()); | |
gtag('set', 'page_title', 'FBIA: '+ia_document.title); | |
gtag('set', 'campaignSource', 'Facebook'); | |
gtag('set', 'campaignMedium', 'Social Instant Article'); | |
gtag('config', 'UA-XXXXXXXX-X'); | |
</script> | |
</iframe> | |
</figure> |
The link you shared is for Google Analytics 4. This gist is five years old and was correct at the time for GA Universal.
Thanks for sharing though!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to use
campaignSource
andcampaignMedium
but it didn't set properly.It seems the campaign data should be:
campaign_source
campaign_medium
As mentioned here
https://support.google.com/analytics/answer/11259997?hl=en