Javascript 如何报告google analytics中的会话变量?

Javascript 如何报告google analytics中的会话变量?,javascript,google-analytics,Javascript,Google Analytics,我是谷歌分析自定义变量的新手。我不明白如何从用户那里获取会话/post变量 我试图捕获$\u会话['usercountry'],并将其添加到GA数据中。它只显示用户注册的国家/地区 来自GA _gaq.push(['_setCustomVar', 2, // This custom var is set to slot #2. Required parameter. 'Country', // The name of the cust

我是谷歌分析自定义变量的新手。我不明白如何从用户那里获取会话/post变量

我试图捕获
$\u会话['usercountry']
,并将其添加到GA数据中。它只显示用户注册的国家/地区

来自GA

_gaq.push(['_setCustomVar',
      2,                   // This custom var is set to slot #2.  Required parameter.
      'Country', // The name of the custom variable.  Required parameter.
      '???',               // The value of the custom variable.  Required parameter.
                           //  (you might set this value by default to No)
      2                    // Sets the scope to session-level.  Optional parameter.
]);

我是不是把usercountry放在我有问号的地方

客户端JavaScript无法访问
$\u会话
,因为集合保存在服务器端

您需要以某种方式向JavaScript公开该值。一种选择是简单地将其包含在PHP的初始输出中:

<script>
    var userCountry = <? echo json_encode($_SESSION['usercountry']) $>;
</script>
然后,您可以将其用于谷歌分析:

_gaq.push([
    '_setCustomVar',
    2,                 // This custom var is set to slot #2.  Required parameter.
    'Country',         // The name of the custom variable.  Required parameter.
    userCountry ,      // The value of the custom variable.  Required parameter.
                       //  (you might set this value by default to No)
    2                  // Sets the scope to session-level.  Optional parameter.
]);

客户端JavaScript无法访问
$\u会话
,因为集合保存在服务器端

您需要以某种方式向JavaScript公开该值。一种选择是简单地将其包含在PHP的初始输出中:

<script>
    var userCountry = <? echo json_encode($_SESSION['usercountry']) $>;
</script>
然后,您可以将其用于谷歌分析:

_gaq.push([
    '_setCustomVar',
    2,                 // This custom var is set to slot #2.  Required parameter.
    'Country',         // The name of the custom variable.  Required parameter.
    userCountry ,      // The value of the custom variable.  Required parameter.
                       //  (you might set this value by default to No)
    2                  // Sets the scope to session-level.  Optional parameter.
]);

谢谢你的帮助。我看了大约20个教程,没有了解这些值是如何传递的,因为GA不知道usercountry是什么。将对其进行测试并查找结果。它是一个字符串。为什么需要“var userCountry=“Country Name”?@DavidMoore是
“国家名称”“
只是前面代码片段中PHP输出的一个示例;JavaScript可能解析的内容。你不需要包括它。谢谢你的帮助。我看了大约20个教程,没有了解这些值是如何传递的,因为GA不知道usercountry是什么。将对其进行测试并查找结果。它是一个字符串。为什么需要“var userCountry=“Country Name”?@DavidMoore“Country Name”只是前面代码段中PHP输出的一个示例;JavaScript可能会解析什么。您不需要包含它。