使用Javascript中的Google跟踪代码管理器将UTM标记传递到Google Analytics(分析) [英] Passing UTM Tags to Google Analytics with Google Tag Manager in Javascript not working

查看:191
本文介绍了使用Javascript中的Google跟踪代码管理器将UTM标记传递到Google Analytics(分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次访问我的页面时,我都尝试直接使用Javascript代码(而不是通过URL)将utms(媒介,源代码)发送到Google Analytics(分析).这就是我要尝试的方式:

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>

由于某些原因,即使Google Analytics(分析)正确实时地跟踪了综合浏览量,它似乎也没有获得中等"和来源".两者都分别显示(无)(直接):

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?

推荐答案

config标签应在设置之后触发.

The config tag should fire AFTER the sets.

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

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

这篇关于使用Javascript中的Google跟踪代码管理器将UTM标记传递到Google Analytics(分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆