node.js - 如何在 Node.js 中使用谷歌标签管理器
问题描述
我将一个简单的电子商务对象推送到dataLayer
客户端的 Google 跟踪代码管理器。它工作正常,但我需要将其移至服务器。
我找到了Google API Node.js 客户端库,但它还很年轻,我找不到任何工作示例。
有没有人设法做到这一点?我将如何使用 node.js 中的 google-api-nodejs-client 完成以下操作?
dataLayer.push({
event: 'purchase',
user: 'user_1234',
transactionId: 'trans_123',
transactionAffiliation: 'Acme Clothing',
transactionTotal: 11.99,
transactionProducts: [
{
id: '1234',
sku: 'SKU47',
name: 'Fluffy Pink Bunnies',
price: 11.99,
quantity: 1
}
]
});
解决方案
我认为你不需要这个或那个库的谷歌 API。您可以只使用Google Measurement Protocol。
因此,对于您的数据层帖子,它将类似于:
对于交易
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
&cid=1234 // user_1234.
&t=transaction // Transaction hit type.
&ti=123 // transaction ID. Required.
&ta=acmeClothing // Transaction affiliation.
&tr=11.99 // Transaction revenue.
然后项目命中
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
&cid=1234 // Anonymous Client ID.
&t=item // Item hit type.
&ti=123 // Transaction ID. Required.
&in=fluffy pink bunnies // Item name. Required.
&ip=11.99 // Item price.
&iq=1 // Item quantity.
&ic=sku47 // Item code / SKU.
推荐阅读
- ansible - Ansible 'register' 返回一个空结果
- php - php json 解析斜杠和引号
- performance - 完全理解现代 pc 架构是否有可能获得比编译器更好的性能?
- android-studio - 防止在不同设备上同时点击一个按钮
- go - 解组不同类型的数组
- javascript - 有没有办法让无限循环在后台运行?
- javascript - 如何在其容器的底部中心对齐按钮?
- python - 通过考虑顺序信息将列表中的字符串元素替换为元组中的元素
- reactjs - Firebase auth 在注册/注册后发送验证链接
- angular - 在没有组件包装器的情况下将 Angular 组件渲染到 DOM