Pass dynamic event label in Google AMP analytics e

2019-05-22 01:32发布

问题:

I want to track an event with google analytics when a link is clicked on my AMP html page. Also I want to pass the link(href) as eventLabel while tracking this event. Is there a way to set the link URL as data-* attribute which then can be passed to google analytics event tracking script. Or is there any other way to do this.

This is pretty standard thing but Google Analytics for AMP page doesn't cover it.

回答1:

I think what you are asking for was recently made available here.

basically, you can use code like

<span id="test1" class="box" data-vars-event-label="22"> Click here </span>

and then use the value in the configuration as ${eventLabel}



回答2:

It seems this is possible. AMP is now supported by Google Analytics as an extended component.

Events are user interactions with content that can be tracked independently from a web page or a screen load. Event tracking with clicked links can now be monitored like:

..,
"trackAnchorClicks": {
"on": "click",
"selector": "a",
"request": "event",
"vars": {
"eventId": "42",
"eventLabel": "clicked on a link"
}