Passing UTM Tags to Google Analytics with Google Tag Manager in Javascript not working

丶灬走出姿态 提交于 2019-12-11 14:40:06

问题


I'm trying to send utms (medium, source) to Google Analytics directly in Javascript code (not via the URL), for every visit to my page. This is how I'm trying to do it:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-52626777-6"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('set', {
        'campaignName':'MyCampaignName',
        'campaignMedium':'MyMedium',
        'campaignSource':'MySource'
    });

    gtag('config', 'UA-11111111-1');

</script>

For some reason, even though Google Analytics is tracking pageviews in real-time correctly, it doesn't seem to be getting the Medium and Source. Both show (none) and (direct) respectively:

Any idea what I'm missing here?


回答1:


The config tag should fire AFTER the sets.

Also gtag('set', {campaign: {medium: 'myMedium', source: 'mySource'}});



来源:https://stackoverflow.com/questions/53031948/passing-utm-tags-to-google-analytics-with-google-tag-manager-in-javascript-not-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!