我在项目中使用谷歌的模型查看器,不幸的是,它将某些事件视为non-interaction: false
,而它们本应是non-interaction: true
。在我的案例中,当模型加载、检测到支持AR的用户以及检测到支持QR的用户时,这些事件都会触发。
如何手动将这些事件的非交互值设置为true?我尝试过类似的解决方案,但没有成功:
export type AnalyticsEvent = {
type: string;
category: string;
action: string;
label: string;
value: number;
nonInteraction: boolean;
};
export const USER_WITH_AR_SUPPORT_TEMPLATE: AnalyticsEvent = {
type: 'event',
category: AR_CATEGORY,
action: 'UserWithArSupport',
label: '',
value: '',
nonInteraction: true,
};
"kind": "javascript-module",
"path": "src/globals/ArEvents.ts",
"declarations": [
{
"kind": "variable",
"name": "userWithArSupportTemplate",
"type": {
"text": "AnalyticsEvent"
},
"default": "{n type: 'event',n category: ARCategory,n action: 'UserWithArSupport',n label: '',n ,n nonInteraction: true}"
},
我也尝试过这里的解决方案,以及几个类似的解决方案。我是否使用了错误的变量名称或索引进行非交互?
根据要求添加更多代码
public sendGaEvent(uaCode: string, eventData: AnalyticsEvent, sku: string, log: boolean) {
...
const instance = this[$analyticsMap].get(uaCode);
const tracker = instance!.tracker;
if (!tracker) {
const queue = instance!.queue;
queue!.enqueue(eventData);
LoggerInstance.log({
sender: this,
message: 'Enqueuing GA event',
force: log
});
} else {
ga(`${tracker}.send`,
eventData.type,
eventData.category,
eventData.action,
eventData.label,
eventData.nonInteraction,
{
hitCallback: () => LoggerInstance.log({
sender: this,
message: 'GA event successfully sent!',
objectToLog: eventData,
force: log
})
}
);
LoggerInstance.log({
sender: this,
message: 'Sending GA event',
force: log
});
}
...
}
编辑:使用@d-_-b的建议,我发现解决方案的正确形式是作为对象传入nonInteraction,如下所示:
ga(
'send',
'event',
'AR_CATEGORY',
'UserWithArSupport',
'label',
{'nonInteraction': true}
);
在将名称"nonInteraction"作为对象传入时,在其周围保留引号显然很重要
对于Universal Analytics,nonInteraction
属性应作为对象传递(请参阅文档(:
ga('send', 'event', 'AR_CATEGORY', 'UserWithArSupport', 'label', {
nonInteraction: true
});
如果您使用的是gtag.js,则需要添加此处所述的non_interaction: true
gtag('event', '<event-name>', {
'event_label': '',
'event_category': 'AR_CATEGORY',
'event_action': 'UserWithArSupport',
'non_interaction': true
});