user2850305
user2850305

Reputation: 397

Pass dynamic event label in Google AMP analytics event tracking

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.

Upvotes: 3

Views: 2203

Answers (2)

Avi
Avi

Reputation: 2383

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}

Upvotes: 4

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17613

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"
}

Upvotes: 2

Related Questions