Google Analytics:将自定义交互字段添加到社交交互中
Google Analytics: add custom interaction field to social interaction
有时我的应用程序中有两个共享按钮 UI(取决于状态)。它们可以共享相同的数据,但位于 UI 的不同部分。我们要分析从哪个按钮(UI 的一部分)执行了共享。我希望在这部分使用 fieldsObject
字段,如 documentation:
中所示
ga('send', 'social', [socialNetwork], [socialAction], [socialTarget], [fieldsObject]);
但是,我能找到的所有示例都只使用前三个字段,通常类似于:
ga('send', {
hitType: 'social',
socialNetwork: 'Twitter',
socialAction: 'share',
socialTarget: 'http://www.example.com/article-01'
});
此外,我不明白文档的含义:
"Note that as with all send commands, the fields passed in the
convenience parameters may also be specified in the fieldsObject
."
我想也许我正在使用 "convenience parameter"。
我的共享代码(来自 Angular 服务):
reportShare(media:string, context: string) {
let pageUrl: string = this.sanitizeURL();
ga('send', {
hitType: 'social',
socialNetwork: media,
socialAction: 'share',
socialTarget: pageUrl,
fieldsObject: context
});
}
我的 Google 分析调试器说:
VM5405 analytics_debug.js:16 Running command: ga("send", {hitType: "social", socialNetwork: "Twitter", socialAction: "share", socialTarget: "/find/1160", fieldsObject: "machine"})
但是然后:
Set called on unknown field: "fieldsObject".
从其余部分可以看出,"fieldsObject" 没有传递:
adSenseId (&a) 1505578412
anonymizeIp (&aip) 1
apiVersion (&v) 1
clientId (&cid) 1703756191.1573561297
encoding (&de) UTF-8
hitType (&t) social
javaEnabled (&je) 0
language (&ul) en-us
location (&dl) http://localhost/find/1160
screenColors (&sd) 24-bit
screenResolution (&sr) 1680x1050
socialAction (&sa) share
socialNetwork (&sn) Twitter
socialTarget (&st) /find/1160
title (&dt) This pagetitle
trackingId (&tid) UA-*********-1
viewportSize (&vp) 1680x916
有没有办法使用社交互动将 fieldsObject 与我的上下文字符串一起传递?
您不应该将该字段命名为对象。
文档指出 fieldObjects 是未在字段签名中传递的对象,这意味着您要发送的任何其他字段。有关 fieldObjects 的文档说明:
An object for specifying any remaining values not specified in any of
the fields parameters.
If a field is set in both a fields parameter and fieldsObject, the
value in fieldsObject will be used.
所以我认为应该是:
ga('send', {
hitType: 'social',
socialNetwork: media,
socialAction: 'share',
socialTarget: pageUrl
},
{
anyOtherLabel: value
}
);
可以在此处查看 ga 命令的文档参考和更多示例:https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#method-details
感谢您的回复!
首先,我已经从 analytics.js 移动到 gtag.js。
我在 GA 界面中创建了自定义维度:
Admin > Custom Definitions > Custom Dimensions,并将其命名为“Share Context”。 gtag 的自定义维度是 documentet here.
然后我更新我的 js 调用:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-**********-*', {
'custom_map': {'dimension1': 'context'},
'custom_map': {'dimension2': 'context'},
'anonymize_ip': true,
'allow_ad_personalization_signals': false
});
在我的报告服务中,我可以调用:
reportShare(media:string, context: string) {
gtag('event', 'Sharing Context', {
'dimension2': context,
'event_category': 'social',
'event_label': media,
'value': this.sanitizedURL
});
}
最后,在 Acquisition > Social > Plugins 下,我可以从 Social Entity > Secondary Dimensions > Custom Dimension > Share Context(这是您在创建自定义维度时提供的名称)。
更多关于 reporting non-standard data as custom dimensions & metrics。
有时我的应用程序中有两个共享按钮 UI(取决于状态)。它们可以共享相同的数据,但位于 UI 的不同部分。我们要分析从哪个按钮(UI 的一部分)执行了共享。我希望在这部分使用 fieldsObject
字段,如 documentation:
ga('send', 'social', [socialNetwork], [socialAction], [socialTarget], [fieldsObject]);
但是,我能找到的所有示例都只使用前三个字段,通常类似于:
ga('send', {
hitType: 'social',
socialNetwork: 'Twitter',
socialAction: 'share',
socialTarget: 'http://www.example.com/article-01'
});
此外,我不明白文档的含义:
"Note that as with all send commands, the fields passed in the convenience parameters may also be specified in the
fieldsObject
."
我想也许我正在使用 "convenience parameter"。 我的共享代码(来自 Angular 服务):
reportShare(media:string, context: string) {
let pageUrl: string = this.sanitizeURL();
ga('send', {
hitType: 'social',
socialNetwork: media,
socialAction: 'share',
socialTarget: pageUrl,
fieldsObject: context
});
}
我的 Google 分析调试器说:
VM5405 analytics_debug.js:16 Running command: ga("send", {hitType: "social", socialNetwork: "Twitter", socialAction: "share", socialTarget: "/find/1160", fieldsObject: "machine"})
但是然后:
Set called on unknown field: "fieldsObject".
从其余部分可以看出,"fieldsObject" 没有传递:
adSenseId (&a) 1505578412
anonymizeIp (&aip) 1
apiVersion (&v) 1
clientId (&cid) 1703756191.1573561297
encoding (&de) UTF-8
hitType (&t) social
javaEnabled (&je) 0
language (&ul) en-us
location (&dl) http://localhost/find/1160
screenColors (&sd) 24-bit
screenResolution (&sr) 1680x1050
socialAction (&sa) share
socialNetwork (&sn) Twitter
socialTarget (&st) /find/1160
title (&dt) This pagetitle
trackingId (&tid) UA-*********-1
viewportSize (&vp) 1680x916
有没有办法使用社交互动将 fieldsObject 与我的上下文字符串一起传递?
您不应该将该字段命名为对象。 文档指出 fieldObjects 是未在字段签名中传递的对象,这意味着您要发送的任何其他字段。有关 fieldObjects 的文档说明:
An object for specifying any remaining values not specified in any of the fields parameters.
If a field is set in both a fields parameter and fieldsObject, the value in fieldsObject will be used.
所以我认为应该是:
ga('send', {
hitType: 'social',
socialNetwork: media,
socialAction: 'share',
socialTarget: pageUrl
},
{
anyOtherLabel: value
}
);
可以在此处查看 ga 命令的文档参考和更多示例:https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#method-details
感谢您的回复! 首先,我已经从 analytics.js 移动到 gtag.js。
我在 GA 界面中创建了自定义维度: Admin > Custom Definitions > Custom Dimensions,并将其命名为“Share Context”。 gtag 的自定义维度是 documentet here.
然后我更新我的 js 调用:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-**********-*', {
'custom_map': {'dimension1': 'context'},
'custom_map': {'dimension2': 'context'},
'anonymize_ip': true,
'allow_ad_personalization_signals': false
});
在我的报告服务中,我可以调用:
reportShare(media:string, context: string) {
gtag('event', 'Sharing Context', {
'dimension2': context,
'event_category': 'social',
'event_label': media,
'value': this.sanitizedURL
});
}
最后,在 Acquisition > Social > Plugins 下,我可以从 Social Entity > Secondary Dimensions > Custom Dimension > Share Context(这是您在创建自定义维度时提供的名称)。
更多关于 reporting non-standard data as custom dimensions & metrics。