问题
Iam using google tag manager it's going very well with click events but when I tried to use datalayer it's not working here is my datalayer
<script>
$('.tag').click(function(event){
dataLayer.push({
'event':'myNewTransaction',
'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
});
});
And in the console when I click on the element with class 'tag' I get this message Tag Not Fired On This Page and this is the message when firing triggers
Event equals myNewTransaction
_event equals My New Transaction
Please help
回答1:
For click events, you should try to stick to using the default click and link click listeners (gtm.click
and gtm.linkClick
), and then triggering your tag to fire based on the clicked class or even the clicked text. It's not as efficient using the dataLayer when you can use what is already built-in. That said, if for some reason you still need to use the dataLayer, then
- your code looks fine,
- you should create a
Custom Event
trigger with the value of the event as "myNewTransaction" - your tag should fire based on this custom event trigger
If you still have issues, then please post screenshots of your tag and trigger configurations.
来源:https://stackoverflow.com/questions/38816513/datalayer-google-tag-manager