简体   繁体   English

如何在Google Analytics(分析)中设置自定义维度

[英]How to set custom dimensions in Google Analytics

I am trying to get custom dimension to be set for and reported in Google Analytics. 我正在尝试为Google Analytics(分析)设置和报告自定义维度。 I'm unable to see any passed values in any report. 我无法在任何报告中看到任何传递的值。

In Google Analytics, for my property, in the settings, under 'Custom dimensions', I've added a custom dimension called 'userId' with index 1 (and scope 'User'). 在Google Analytics(分析)中,对于我的媒体资源,在设置中的“自定义维度”下,我添加了一个名为“ userId”的自定义维度,索引为1(范围为“用户”)。

Based on this page , my tracking script in my site's pages header is this: 根据此页面 ,我网站页面标题中的跟踪脚本是这样的:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-XXXXXX', {
  'custom_map': {
    'dimension1': 'userId'
  }
});

var dimensionValue = <?php print $userId; ?>;
gtag('event', 'userId_dimension', {'userId': dimensionValue});

($userId is an integer.) ($ userId是整数。)

In a report like 'Behaviour' -> 'Site content' -> 'Pages', I'm able to select a secondary dimension, including 'userId'. 在“行为”->“站点内容”->“页面”之类的报告中,我可以选择一个辅助维度,包括“ userId”。 When selecting this secondary dimension, the resulting table has no rows. 选择此次级维度时,结果表没有行。 Even though, when inspecting my pages, the tracking code appears to pass the userId, and Google Analytics records visits that pass the userId. 即使在检查我的页面时,跟踪代码似乎传递了userId,并且Google Analytics(分析)记录了传递了userId的访问。

What am I doing wrong? 我究竟做错了什么?

It seems this resolved itself after a while. 似乎过了一会儿,问题解决了。

However, I found that creating multiple events for different custom dimensions did not seem to register those values. 但是,我发现为不同的自定义维度创建多个事件似乎并没有注册这些值。

So, this is what I ended up with: 因此,这就是我最终得到的结果:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-XXXXXX-1', {
    'custom_map': {
        'dimension1': 'userId',
        'dimension2': 'userName',
        'dimension3': 'clientId',
        'dimension4': 'clientName'
    }
});

<?php
    if (isset($_SESSION["user"])) {
        $gt["userId"] = $_SESSION["user"]["iID"];
        $gt["userName"] = addslashes($_SESSION["user"]["tFirstName"]." ".$_SESSION["user"]["tLastName"]);
        $gt["clientId"] = 0;
        $gt["clientName"] = '';

        if (isset($_SESSION["user"]["clients"])) {
            if (isset($_SESSION["user"]["clients"][0])) {
                $gt["clientId"] = $_SESSION["user"]["clients"][0]["iID"];
                $gt["clientName"] = addslashes($_SESSION["user"]["clients"][0]["tName"]);
            }
        }
        ?>
        gtag('event', 'add_dimensions', {
            'userId' : <?php print $gt["userId"]; ?>,
            'userName' : '<?php print $gt["userName"]; ?>',
            'clientId' : <?php print $gt["clientId"]; ?>,
            'clientName' : '<?php print $gt["clientName"]; ?>'
        });
        <?php       
    }
?>

This now appears to work as expected. 现在,这似乎可以正常工作。

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

相关问题 Google Analytics(分析)自定义维度 - Google analytics custom dimensions 如何在Google Analytics(分析)中取得具有自订维度的clientId - How to get clientId with custom dimensions in google analytics 如何注册一个独特的页面视图以及如何使用自定义维度Google Analytics - How to register a uniquePageview and how to use custom dimensions google analytics ionic应用程序中的Google Analytics(分析)自定义维度 - Google Analytics custom dimensions within ionic app 随时修改Google Analytics自定义维度 - Modify Google Analytics custom dimensions on the go Google Analytics 不发送带有网页浏览点击的自定义维度 - Google analytics not sending custom dimensions with pageview hits Google Analytics(分析)使用gtag发送两个自定义维度 - Google Analytics send two custom dimensions with gtag 在Google AnalyticsAPI中使用和查询自定义维度 - Using and querying Custom Dimensions in Google Analytics API Google Analytics-如何使用DataLayer设置自定义变量 - Google Analytics - how to set custom variable with DataLayer 如何为与之前进行的相同调用/匹配的Google Analytics(分析)自定义维度添加代码,并添加一些自定义维度(需要花费一些时间来计算) - How to add code for Google Analytics custom dimensions for the same call/hit made prior, with some custom dimensions ( which take time to calculate )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM