4.1K members online now
4.1K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
Guide Me

GA Persistence of Virtual Pageviews

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

This is an advanced question.


I'm working on a B2B site that has dropdowns (HTML `select` elements with child `option` elements used frequently) for industry and/or products etc.


The homepage allows users to select their industry to see products specific to them, as do many other pages.


Note: I am implementing GA (Universal) via GTM but this is—I think—a GA question.


For some places, GA virtual pageviews (upon options selected on the dropdowns) are perfect but on the home page (and others) I am not so sure.


Let's say that when a user selects an option on the homepage (essentially a filter) I set a virtual pageview like:

`page: /virtual/industry1`

`title: Industry 1 Selected - Homepage`


How does that persist?


If, after that, a user scrolls down the page and clicks an outbound link (separate tags and triggers), will the page path that the link click occurred on be reported as `/` or as `/virtual/industry1`?

Re: GA Persistence of Virtual Pageviews

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

Hi, thanks for the explanation.


Let me make sure I understand this correctly:


The approach I have been using is that when an option is selected it pushes a custom event to the `dataLayer` (here's the custom HTML/JS)

  (function() {
    var selectIndustry = document.getElementById('industry');
    selectIndustry.addEventListener('change', function(e) {
        event: 'industrySelected',
        selectedIndustry: this.value
    }, true);

I then have a tag that is triggered by that custom event (`industrySelected`) that is a GA pageview tag with `fields to set` for `page` where I capture the value of `selectedIndustry` .


It seems like this is exactly what you're suggesting with the exception of the name of the dataLayer variable (`selectedIndustry` vs. `virtualPage`)...but the name of the variable isn't important.


If I set a pageview tag to fire on that event and override the `fields to set` for `page` then it's still the same result.


What am I missing?


How would I use that custom dataLayer variable to fire a virtual pageview and still keep my actual page/path the same?