Daveh0
Daveh0

Reputation: 1000

google tag manager - how to track Virtual Page-views with Element Visibility trigger

I have a single page web site containing 4 main sections with unique ID attributes:

Using Google Tag Manager, I want to send a virtual pageview to Google Analytics for each of these <section> elements anytime one of them scrolls into view and stays there for at least a second.

I start by creating an Element Visibility trigger. I specify the CSS selector, section[id^="section-"] and leave the default value of 1000 ms.

I then create a Universal Analytics tag for pageview using that trigger. Everything works as desired except for the fact that all that is logged for the pageview is "/" (or index.php). I know that I can add a field for "page" but I can't seem to find a variable that will give the ID of the element causing the trigger to fire.

I know that by writing a custom listener for the trigger, I can capture that data, but the Element Visibility trigger is quite robust, so I'd like to continue using it. Has anyone figured out a way to create a custom variable for the element's ID? or is there perhaps a built-in variable I'm missing?

Upvotes: 0

Views: 816

Answers (1)

Дмитро Булах
Дмитро Булах

Reputation: 3847

you can get element ID of the element that triggered a tag from dataLayer, it's recorded as gtm.elementId. you may find useful this extensive overview by Simo Ahava: https://www.simoahava.com/analytics/element-visibility-trigger-google-tag-manager/

Upvotes: 1

Related Questions