Skip to content

Instantly share code, notes, and snippets.

@danieljwonder
Created November 27, 2017 05:39
Show Gist options
  • Select an option

  • Save danieljwonder/a22b13f92fdaaac2748fe9359222e215 to your computer and use it in GitHub Desktop.

Select an option

Save danieljwonder/a22b13f92fdaaac2748fe9359222e215 to your computer and use it in GitHub Desktop.
Google Analytics Global Site Tag (gtag.js) for Facebook Instant Articles (Full Snippet)
<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>
@firmlab
Copy link
Copy Markdown

firmlab commented Jan 9, 2023

I tried to use campaignSource and campaignMedium 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

@danieljwonder
Copy link
Copy Markdown
Author

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