简体   繁体   English

使用 Google Tag Manager 和 Google Analytics 跟踪产品查看次数

[英]Product view count tracking with Google Tag Manager and Google Analytics

In a symfony e-commerce project, to create a product view frequency report such that view count is increased when the user navigate to /product/detail/{id} .在 symfony 电子商务项目中,创建产品查看频率报告,以便在用户导航到/product/detail/{id}时增加查看次数。 I am using Google Tag Manager and Analytics using the following as reference:我正在使用谷歌标签管理器和分析,使用以下作为参考:
https://support.usabilla.com/hc/en-us/articles/360015738812-Integration-with-Google-Analytics-using-GTM-Data-Layer# https://support.usabilla.com/hc/en-us/articles/360015738812-Integration-with-Google-Analytics-using-GTM-Data-Layer#

Google Tag Manager Setting谷歌标签管理器设置

1. Create trigger 1.创建触发器

Trigger Type: Page View
Trigger Fire On: Some Page Views (Page path : contains : /products/detail)

2. Create variables 2. 创建变量

Name: dlv - productName
Variable Type: Data Layer Variable
Name: product.productName
  1. Create Tag创建标签
Tag Type: Google Analytics: Universal Analytics
Track Type: Event
Category: Product Detail // static text
Action: View {{dlv - productName }}
Label: {{ dlv - productName }}
Value: {{ dlv - productName }}
Google Analytics Settings: {{ Google_Analytics_Track_ID_Settings }}
Tiggering: {{ Trigger_created_in_step_1 }}

Product Page产品页面

<script>
    dataLayer.push({
        'product': {
            'productId': {{ Product.id }},
            'productName': '{{ Product.name }}'
        }
    });
</script>

I can see dataLayer array is being sent to Google Tag Manager in the debug window.我可以在调试 window 中看到dataLayer数组正在发送到 Google Tag Manager。 In Google Analytics > Behavior > Events > Top Events , I can see Product Detail in Event Category column.Google Analytics > Behavior > Events > Top Events中,我可以在 Event Category 列中看到 Product Detail。 When I click the link the Event Action only shows View and Event Label is (not set) .当我单击链接时,事件操作仅显示View和 Event Label is (not set) I want to create a tabular report like Product Detail: View Orange: 3 , Product detail: View Apple: 4 .我想创建一个表格报告,例如Product Detail: View Orange: 3Product detail: View Apple: 4

Cross-check that your {{ dlv - productName }} variable is properly populated and the value is available to the tag at the moment tag fires.交叉检查您的{{ dlv - productName }}变量是否已正确填充,并且在标签触发时该值可用于标签。 If its value is populated later then the tag fires your event action would be tracked as (not set) .如果稍后填充其值,则触发您的事件操作的标记将被跟踪为(not set) If this is the case consider changing your trigger type to Window loaded or other event so the tag would grab the proper value from DL.如果是这种情况,请考虑将触发类型更改为 Window 加载或其他事件,以便标签从 DL 中获取正确的值。

Although the key concept is provided in earlier answer, there are other solutions as well, which might give you better results.尽管在较早的答案中提供了关键概念,但还有其他解决方案可能会给您带来更好的结果。

So basically, you need to ensure, that the data you want to use from the dataLayer is available, when your tag is launched.因此,基本上,您需要确保在启动标签时,您想要从 dataLayer 使用的数据可用。

To achieve this, you can delay the tag to Window Loaded event, but you should be aware, that based on the size and content type of your page, a given percentage of your users will not have Window Loaded trigger launched, so you could miss part of your data.为此,您可以将标签延迟到 Window 加载事件,但您应该注意,根据页面的大小和内容类型,给定百分比的用户不会启动 Window 加载触发器,因此您可能会错过您的数据的一部分。 (They close the browser, navigate to other page before Window Loaded is reached.) (他们关闭浏览器,在 Window 加载之前导航到其他页面。)

So an other option is to have the data pushed into the dataLayer before GTM is initialized .所以另一种选择是在 GTM 初始化之前将数据推送到 dataLayer 中 So your code looked something like this, placed above main GTM code in <head> :所以你的代码看起来像这样,放在<head>的主要 GTM 代码之上:

<script>
    var dataLayer = window.dataLayer || [];  //define dataLayer, while avoiding overwriting its content
    dataLayer.push({
        'product': {
            'productId': {{ Product.id }},
            'productName': '{{ Product.name }}'
        }
    });
</script>

This way, your page view event will already see this data.这样,您的页面查看事件将已经看到此数据。

An other option would be to leave your code at it's current place, but to specify a triggering event , to let GTM know about the new data:另一种选择是将代码保留在当前位置,但要指定触发事件,让 GTM 知道新数据:

<script>
    dataLayer.push({
        'event': 'productDataReady',
        'product': {
            'productId': {{ Product.id }},
            'productName': '{{ Product.name }}'
        }
    });
</script>

This way, you need to modify the trigger of your tag to be a Custom Event, matching the string used in the event variable.这样,您需要将代码的触发器修改为自定义事件,匹配event变量中使用的字符串。 In this case, the data is available at this specific event.在这种情况下,数据在此特定事件中可用。

Also, please note, that {{ dlv - productName }} should probably not used as event value, as Google Analytics accepts only integer values, while product name is likely to be a string.另外,请注意, {{ dlv - productName }}可能不应用作事件值,因为 Google Analytics 仅接受 integer 值,而产品名称可能是字符串。

An other consideration, is that you haven't specified (or at least haven't included it in your post), that the event should be non-interaction.另一个考虑因素是您没有指定(或至少没有将其包含在您的帖子中),该事件应该是非交互的。 If you generate an interactive event with your page load, assuming you also fire a pageview hit, you'll get an extremely low bounce rate.如果您在页面加载时生成交互式事件,假设您还触发了网页浏览命中,那么您将获得极低的跳出率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google跟踪代码管理器和Google Analytics(分析)跟踪 - Google Tag Manager and Google Analytics tracking Google跟踪代码管理器中的Google Analytics事件跟踪 - Google Analytics Event Tracking in Google Tag Manager 移动跟踪Google Analytics(分析)和Google Tag Manager - Mobile tracking google analytics and google tag manager 使用Google Tag Manager电子商务跟踪到Analytics(分析) - Tracking with Google Tag Manager Ecommerce to Analytics Google 跟踪代码管理器 - 产品页面上的图像跟踪 - Google Tag Manager - Image Tracking on product page 使用Google跟踪代码管理器时保持Google Analytics(分析)跟踪 - Keep google analytics tracking while using google tag manager 如何获取Google跟踪代码管理器事件跟踪以发送到Google Analytics(分析)? - How to get Google Tag Manager Event Tracking to send to Google Analytics? 点击 Google Tag Manager 和 Google Analytics Conversion 上的元素跟踪 - Click Element Tracking on Google Tag Manager & Google Analytics Conversion 使用Google跟踪代码管理器和Google Analytics(分析)跟踪提交的表单值 - Tracking Submitted Form Values with Google Tag Manager and Google Analytics 通过Google跟踪代码管理器的Google Analytics(分析)未跟踪根网址/ - Google Analytics via Google Tag Manager not tracking root url /
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM