Google Analytics中不会跟踪TagManager的DataLayer

时间:2022-01-13 15:21:12

I am able to dynamically construct the datalayer for tagmanager. But it is not tracked in Google Analytics.

我能够为tagmanager动态构建数据层。但是Google Analytics中没有跟踪它。

From the documentation provide by google, we need not use datalayer.push[] as it is rendered before the tagmanager codes. My code for this is:

从谷歌提供的文档中,我们不需要使用datalayer.push [],因为它在tagmanager代码之前呈现。我的代码是:

<script>
dataLayer = [{
"transactionId": "4NOV2013_4830a18f-15fd-4cc5-a035-0e513d3f73bb",
"transactionAffiliation":"Registration",
"transactionTotal": 0,
"transactionProducts": [{
"sku": "Lead",
"name":"Lead",
"price": 0,
"quantity": 1
}]
    }];

</script>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-DEMO"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-DEMO');</script>
<!-- End Google Tag Manager -->

2 个解决方案

#1


0  

Sridhar, it seems that you are listing all required parameters, so this should work once the e-commerce tag is setup correctly. Make sure you add a new tag for e-commerce transactions:

Sridhar,您似乎列出了所有必需的参数,因此一旦正确设置了电子商务标签,这应该可以使用。确保为电子商务交易添加新标签:

  • Tag Type: Google/Universal Analytics
  • 代码类型:Google / Universal Analytics
  • Track Type: Transaction
  • 跟踪类型:交易

Full official documentation from Google Tag Manager team.

Google跟踪代码管理器小组的完整官方文档。

Also make sure you use correct version of GTM container snippet. I can see you have replaced one of the container IDs with GTM-DEMO, but the other one is still visible (html?id=GTM-KMSLVD).

另外,请确保使用正确版本的GTM容器代码段。我可以看到你用GTM-DEMO替换了一个容器ID,但另一个仍然可见(html?id = GTM-KMSLVD)。

Double check the container is working correctly, then use Preview/Debug feature to see if the tags fires together with GA Debug in Chrome (see the attached picture). If there is anything wrong (like argument type), GA Debug will list all the error messages in the browser console.

仔细检查容器是否正常工作,然后使用预览/调试功能查看标签是否与Chrome中的GA Debug一起激活(参见附图)。如果有任何错误(如参数类型),GA Debug将在浏览器控制台中列出所有错误消息。

Google Analytics中不会跟踪TagManager的DataLayer

#2


-1  

You are missing several syntaxes for e-commerce to work in Universal Analytics. Have you read the documentation on https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce?

您缺少几种电子商务语法,可以在Universal Analytics中使用。您是否阅读了有关https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce的文档?

What you have now is basically only the transaction saved within GTM, so there are several ways to go about doing the actual transaction. You could set up rules within GTM to fire the transaction if it sees a specific event within the dataLayer, which looks like what you have tried? If so, then you need to create a rule to fire the transaction once it sees this data.

您现在拥有的基本上只是GTM中保存的事务,因此有几种方法可以进行实际的事务处理。如果在dataLayer中看到特定事件,您可以在GTM中设置规则以触发事务,这看起来像您尝试过的那样?如果是这样,那么您需要创建一个规则来在事务看到此数据后触发该事务。

Or, you could just send the whole transaction within the checkout page where the dataLayer itself is placed.

或者,您可以在结帐页面中发送整个交易,其中放置了dataLayer。

For this to work, and what I am seeing is missing, is the call for the ecommerce javascript library.

为了这个工作,我所看到的是缺少,是电子商务JavaScript库的调用。

ga('require', 'ecommerce', 'ecommerce.js');

Also, your not sending the transaction itself using ga('ecommerce:send');.

此外,您不使用ga发送交易本身('ecommerce:send');.

Some key components from the documentation from Google is, when using the ecommerce.js library:

使用ecommerce.js库时,Google文档中的一些关键组件是:

To load the ecommerce plugin, use the following command:

要加载电子商务插件,请使用以下命令:

ga('require', 'ecommerce', 'ecommerce.js');

This command must occur after you create your tracker object and before you use any of the ecommerce specific functionality.

创建跟踪器对象之后以及使用任何电子商务特定功能之前,必须执行此命令。

ga('ecommerce:addTransaction', {
  'id': '1234',                     // Transaction ID. Required.
  'affiliation': 'Acme Clothing',   // Affiliation or store name.
  'revenue': '11.99',               // Grand Total.
  'shipping': '5',                  // Shipping.
  'tax': '1.29'                     // Tax.
});

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

ga('ecommerce:send');

UPDATE: After a comment from questioner, I'd like to add this to my answer. What needs to be done is to set up the transaction itself to be tracked within GTM. To do this, follow theese steps:

更新:在提问者的评论之后,我想将此添加到我的答案中。需要做的是设置要在GTM中跟踪的事务本身。为此,请按照以下步骤操作:

  1. Create a new tag and name it, for example, "Track transaction".
  2. 创建一个新标记并为其命名,例如“跟踪事务”。
  3. Select "Universal Analytics" as tag type
  4. 选择“Universal Analytics”作为标记类型
  5. Select "Transaction" as track type
  6. 选择“交易”作为轨道类型
  7. Add a new rule and name it, for example, "Conversion page"
  8. 添加新规则并为其命名,例如“转换页”
  9. Enter URL contains "thank-you-page" and add another field
  10. 输入URL包含“thank-you-page”并添加另一个字段
  11. Enter event equals gtm.dom
  12. 输入事件等于gtm.dom

Save and publish and see if this solves your issue.

保存并发布,看看这是否解决了您的问题。

#1


0  

Sridhar, it seems that you are listing all required parameters, so this should work once the e-commerce tag is setup correctly. Make sure you add a new tag for e-commerce transactions:

Sridhar,您似乎列出了所有必需的参数,因此一旦正确设置了电子商务标签,这应该可以使用。确保为电子商务交易添加新标签:

  • Tag Type: Google/Universal Analytics
  • 代码类型:Google / Universal Analytics
  • Track Type: Transaction
  • 跟踪类型:交易

Full official documentation from Google Tag Manager team.

Google跟踪代码管理器小组的完整官方文档。

Also make sure you use correct version of GTM container snippet. I can see you have replaced one of the container IDs with GTM-DEMO, but the other one is still visible (html?id=GTM-KMSLVD).

另外,请确保使用正确版本的GTM容器代码段。我可以看到你用GTM-DEMO替换了一个容器ID,但另一个仍然可见(html?id = GTM-KMSLVD)。

Double check the container is working correctly, then use Preview/Debug feature to see if the tags fires together with GA Debug in Chrome (see the attached picture). If there is anything wrong (like argument type), GA Debug will list all the error messages in the browser console.

仔细检查容器是否正常工作,然后使用预览/调试功能查看标签是否与Chrome中的GA Debug一起激活(参见附图)。如果有任何错误(如参数类型),GA Debug将在浏览器控制台中列出所有错误消息。

Google Analytics中不会跟踪TagManager的DataLayer

#2


-1  

You are missing several syntaxes for e-commerce to work in Universal Analytics. Have you read the documentation on https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce?

您缺少几种电子商务语法,可以在Universal Analytics中使用。您是否阅读了有关https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce的文档?

What you have now is basically only the transaction saved within GTM, so there are several ways to go about doing the actual transaction. You could set up rules within GTM to fire the transaction if it sees a specific event within the dataLayer, which looks like what you have tried? If so, then you need to create a rule to fire the transaction once it sees this data.

您现在拥有的基本上只是GTM中保存的事务,因此有几种方法可以进行实际的事务处理。如果在dataLayer中看到特定事件,您可以在GTM中设置规则以触发事务,这看起来像您尝试过的那样?如果是这样,那么您需要创建一个规则来在事务看到此数据后触发该事务。

Or, you could just send the whole transaction within the checkout page where the dataLayer itself is placed.

或者,您可以在结帐页面中发送整个交易,其中放置了dataLayer。

For this to work, and what I am seeing is missing, is the call for the ecommerce javascript library.

为了这个工作,我所看到的是缺少,是电子商务JavaScript库的调用。

ga('require', 'ecommerce', 'ecommerce.js');

Also, your not sending the transaction itself using ga('ecommerce:send');.

此外,您不使用ga发送交易本身('ecommerce:send');.

Some key components from the documentation from Google is, when using the ecommerce.js library:

使用ecommerce.js库时,Google文档中的一些关键组件是:

To load the ecommerce plugin, use the following command:

要加载电子商务插件,请使用以下命令:

ga('require', 'ecommerce', 'ecommerce.js');

This command must occur after you create your tracker object and before you use any of the ecommerce specific functionality.

创建跟踪器对象之后以及使用任何电子商务特定功能之前,必须执行此命令。

ga('ecommerce:addTransaction', {
  'id': '1234',                     // Transaction ID. Required.
  'affiliation': 'Acme Clothing',   // Affiliation or store name.
  'revenue': '11.99',               // Grand Total.
  'shipping': '5',                  // Shipping.
  'tax': '1.29'                     // Tax.
});

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

ga('ecommerce:send');

UPDATE: After a comment from questioner, I'd like to add this to my answer. What needs to be done is to set up the transaction itself to be tracked within GTM. To do this, follow theese steps:

更新:在提问者的评论之后,我想将此添加到我的答案中。需要做的是设置要在GTM中跟踪的事务本身。为此,请按照以下步骤操作:

  1. Create a new tag and name it, for example, "Track transaction".
  2. 创建一个新标记并为其命名,例如“跟踪事务”。
  3. Select "Universal Analytics" as tag type
  4. 选择“Universal Analytics”作为标记类型
  5. Select "Transaction" as track type
  6. 选择“交易”作为轨道类型
  7. Add a new rule and name it, for example, "Conversion page"
  8. 添加新规则并为其命名,例如“转换页”
  9. Enter URL contains "thank-you-page" and add another field
  10. 输入URL包含“thank-you-page”并添加另一个字段
  11. Enter event equals gtm.dom
  12. 输入事件等于gtm.dom

Save and publish and see if this solves your issue.

保存并发布,看看这是否解决了您的问题。