Tracking events using Google Tag Manager

霸气de小男生 提交于 2019-12-22 09:39:15

问题


I've been attempting to pick up a bit of Javascript for analytics since starting to use Google Tag Manager. Currently, I'd like to track exit links and am using the following custom html snippet:

<script type="text/javascript"> 

$(document).ready(function(){ 

    $('.app-cta a').onClick=_gaq.push(['_trackEvent', 'App', 'Click', 'iOS']);

});
</script>

The firing rules are:

{{event}} equals GAevent

I then tried a firing rule:

{{url}} matches RegEx .*

No luck. Nothing being picked up in Google Analytics nor in HTTPfox.

I'm still getting my head around Google Tag Manager.

Can anyone see what I'm doing wrong here?


回答1:


You need to use dataLayer.push, not _gaq.push, and your onClick function is incorrect. Should look something like this:

<script>
    $('.app-cta a').click(function(event){
        dataLayer.push({
            'event':'GAevent',
            'eventCategory': 'App', //create a datalayer variable macro called eventCategory
            'eventAction': 'Click', //create a datalayer variable macro called eventAction
            'eventLabel': 'iOS' //create a datalayer variable macro called eventLabel
        });
    });
</script>

This Custom HTML tag should fire {{url}} matches RegEx .*

In addition to this setup, you'll need to create a new Google Analytics tag with track type = Event. Add your macros (eventCategory, etc) that you created into the Event Tracking Parameters, and set the firing rule to {{event}} equals GAevent.



来源:https://stackoverflow.com/questions/18192982/tracking-events-using-google-tag-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!