node.js - 如何在 Node.js 中使用谷歌标签管理器

标签 node.js google-analytics google-apis-explorer google-api-nodejs-client

我将一个简单的电子商务对象推送到客户端的 Google 跟踪代码管理器 dataLayer。它工作正常,但我需要将其移动到服务器。

我找到了 Google API Node.js Client Library但它还很年轻,我找不到任何可用的例子。

有没有人设法做到这一点?我将如何使用 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
    }
  ]
});

最佳答案

我认为您不需要为这个或那个库使用 google API。您可以只使用 Google Measurement Protocol .

Here's an example of how they build the call.

因此对于您的数据层帖子,它将类似于:

为了交易

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.

关于node.js - 如何在 Node.js 中使用谷歌标签管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57915339/

相关文章:

node.js - Bigquery在Node JS中的云函数中加载,无需等待即可获取作业ID

javascript - 数组数组包含数组javascript

mysql - 如何使用NodeJS在sequelize中编写具有多个where的子查询

android - 安卓上的谷歌分析

node.js - 无法使用gmail api Node js发送邮件

android - Google Speech API 的 Base64 解码失败

javascript - 在 nodejs 中使用 googleapis 的服务帐户和 JWT 身份验证发送邮件失败

node.js - 无法连接到docker mongodb

google-analytics - 获取登陆页面的协议(protocol) http/https 部分

javascript - 在 Highcharts.js 上显示 Google Analytics 30 天流量