簡體   English   中英

使用 Google Tag Manager 和 Google Analytics 跟蹤產品查看次數

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

在 symfony 電子商務項目中,創建產品查看頻率報告,以便在用戶導航到/product/detail/{id}時增加查看次數。 我正在使用谷歌標簽管理器和分析,使用以下作為參考:
https://support.usabilla.com/hc/en-us/articles/360015738812-Integration-with-Google-Analytics-using-GTM-Data-Layer#

谷歌標簽管理器設置

1.創建觸發器

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

2. 創建變量

Name: dlv - productName
Variable Type: Data Layer Variable
Name: product.productName
  1. 創建標簽
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 }}

產品頁面

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

我可以在調試 window 中看到dataLayer數組正在發送到 Google Tag Manager。 Google Analytics > Behavior > Events > Top Events中,我可以在 Event Category 列中看到 Product Detail。 當我單擊鏈接時,事件操作僅顯示View和 Event Label is (not set) 我想創建一個表格報告,例如Product Detail: View Orange: 3Product detail: View Apple: 4

交叉檢查您的{{ dlv - productName }}變量是否已正確填充,並且在標簽觸發時該值可用於標簽。 如果稍后填充其值,則觸發您的事件操作的標記將被跟蹤為(not set) 如果是這種情況,請考慮將觸發類型更改為 Window 加載或其他事件,以便標簽從 DL 中獲取正確的值。

盡管在較早的答案中提供了關鍵概念,但還有其他解決方案可能會給您帶來更好的結果。

因此,基本上,您需要確保在啟動標簽時,您想要從 dataLayer 使用的數據可用。

為此,您可以將標簽延遲到 Window 加載事件,但您應該注意,根據頁面的大小和內容類型,給定百分比的用戶不會啟動 Window 加載觸發器,因此您可能會錯過您的數據的一部分。 (他們關閉瀏覽器,在 Window 加載之前導航到其他頁面。)

所以另一種選擇是在 GTM 初始化之前將數據推送到 dataLayer 中 所以你的代碼看起來像這樣,放在<head>的主要 GTM 代碼之上:

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

這樣,您的頁面查看事件將已經看到此數據。

另一種選擇是將代碼保留在當前位置,但要指定觸發事件,讓 GTM 知道新數據:

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

這樣,您需要將代碼的觸發器修改為自定義事件,匹配event變量中使用的字符串。 在這種情況下,數據在此特定事件中可用。

另外,請注意, {{ dlv - productName }}可能不應用作事件值,因為 Google Analytics 僅接受 integer 值,而產品名稱可能是字符串。

另一個考慮因素是您沒有指定(或至少沒有將其包含在您的帖子中),該事件應該是非交互的。 如果您在頁面加載時生成交互式事件,假設您還觸發了網頁瀏覽命中,那么您將獲得極低的跳出率。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM