简体   繁体   中英

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} . 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#

Google Tag Manager Setting

1. Create trigger

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

2. Create variables

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. In Google Analytics > Behavior > Events > Top Events , I can see Product Detail in Event Category column. When I click the link the Event Action only shows View and Event Label is (not set) . I want to create a tabular report like Product Detail: View Orange: 3 , Product 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. If its value is populated later then the tag fires your event action would be tracked as (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.

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.

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. (They close the browser, navigate to other page before Window Loaded is reached.)

So an other option is to have the data pushed into the dataLayer before GTM is initialized . So your code looked something like this, placed above main GTM code in <head> :

<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:

<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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM