Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Analytics Global Site Tag (gtag.js) for Facebook Instant Articles
<!-- Global site tag (gtag.js) - Google Analytics -->
<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>
@adlugopolski

This comment has been minimized.

Copy link

@adlugopolski adlugopolski commented May 15, 2018

@danielmcclure Does setting campaignSource like this actually works for you? Just tried to set those but no data is being registered in the Campaigns either way...

@hackhat

This comment has been minimized.

Copy link

@hackhat hackhat commented Aug 22, 2018

Not working

@samitny

This comment has been minimized.

Copy link

@samitny samitny commented Dec 19, 2018

Not working here either.

@adamlytics

This comment has been minimized.

Copy link

@adamlytics adamlytics commented Jan 15, 2019

Same, not working

@adamlytics

This comment has been minimized.

Copy link

@adamlytics adamlytics commented Jan 15, 2019

Check this out: https://stackoverflow.com/questions/50231721/how-to-track-utm-source-in-google-analytics-using-gtag

Do it this way:
gtag('set', 'campaign', { medium: '', source: '', name: '', content: '' }); // code to send pageview / event

Or if you are doing this with the initial page view:
gtag('config', ''UA-XXXXXXX-X', { campaign: { medium: '', source: '', name: '', content: '' } );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.