简体   繁体   English

Google Analytics(分析)使用gtag发送两个自定义维度

[英]Google Analytics send two custom dimensions with gtag

currently on my website i'm trying to send two custom dimensions to Analytics. 目前在我的网站上,我正在尝试向Analytics(分析)发送两个自定义维度。

One is client_id, the other is environment. 一个是client_id,另一个是环境。 Both are saved the same way: Name, scope: hit and both active. 两者的保存方式相同:名称,作用域:命中且均处于活动状态。 The only differences are the names and index. 唯一的区别是名称和索引。

In my code I have this: 在我的代码中,我有:

  function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'GTAG-UA', {
        'custom_map': {
            'dimension1': 'client_id',
            'dimension2': 'environment'
        }
    });

    gtag('event', 'analytics', {'client_id': env.client_id, 'environment': env.baseurl});

The thing is, when i'm doing a custom report with custom dimension as client_id, everything is fine, I have the datas, but when i'm doing one with environment, no data, like if nothing was sent. 关键是,当我使用自定义维度作为client_id进行自定义报告时,一切都很好,我有了数据,但是当我在环境中进行操作时,没有数据,就像什么都没发送一样。

I checked the env.baseurl and it's correct, it's set. 我检查了env.baseurl,它是正确的,它已设置。 The only difference between client_id and environment is that client_id is an int, while environment is a url (so a string). client_id和environment之间的唯一区别是client_id是一个int,而environment是一个url(所以是一个字符串)。

Is there any restriction on strings or maybe on URLs ? 是否对字符串或URL有任何限制? Or maybe there's something wrong in my code ? 或者也许我的代码有问题?

Thanks for your help guys ! 感谢您的帮助!

There are two potential issues to rule out. 有两个潜在问题需要排除。

1) Is the data being sent to GA? 1)数据是否正在发送到GA? You can verify this by looking at the network request tab and looking for the event going to https://www.google-analytics.com/r/collect and check out the parameters it is sending. 您可以通过查看网络请求标签并查找前往https://www.google-analytics.com/r/collect的事件并检查其发送的参数来验证这一点。 Here is a simple translation: 这是一个简单的翻译:

ec: Event Category
ea: Event Action <---- You should see this one based on your example
el: Event Label
cd1: client_id
cd2: environment

If you see cd1 and cd2 being populated, then most likely the data is being sent properly. 如果您看到cd1和cd2正在填充,则很可能数据已正确发送。

2) Are you looking in the right place for this data? 2)您是否在正确的位置寻找这些数据? If it's being sent to GA, have you defined what the custom dimension is in the admin section of GA? 如果要发送给GA,您是否在GA的admin部分中定义了自定义维度?

3) Maybe environment is a protected name? 3)也许环境是受保护的名称? It wouldn't be the craziest guess. 这不是最疯狂的猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM