AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2.9K members online now
2.9K 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
star_border
Reply

Google Tag Manager - overwrites {{virtual page view}} with {{url hostname}}?

Explorer ✭ ✭ ☆
# 1
Explorer ✭ ✭ ☆

I came across a very strange situation:

I have a AJAX website with several pages. Some of the pages have one screen but some have multiple screens to which I assigned virtual page names. By trial and error testing I found out that events with "non-interaction" flag set to "False" overwrite virtual page names, for example:

mydomain.com/form/car/selected ('/car/selected' being virtual page name) will be overwritten to mydomain.com/form/ when any interactive event happens on page (for example gtm.timer used for adjusted bounce rate measurement).

 

To counter it I set field "page" to {{url path}}/{{virtual page name}} in all interactive UA Event tags (exactly the same way as in virtual pageview tag).  In this case {{virtual page name}} is dataLayer variable that gets hardcoded page name. It works well for all virtual pages as it overwrites previous virtual pageview name with the same name.
The problem happens however when page doesn't have any virtual pages. In this case {{virtual page name}} variable resolves to 'undefined' and interactive UA event instead of {{url path}}/{{virtual page name}} (as it's set in GTM) is reported as {{url path}}/{{url hostname}}

 

For example: instead of /mydomain/form/ it reports /mydomain/form/mydomain.com

 

Do you have any idea as to why it may be that way and what can I do about it?

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Olgierd N
May 2016

Re: Google Tag Manager - overwrites {{virtual page view}} with {{url hostname}}?

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆
Hi Andrzej,

To fix this you may want to write a custom javascript for the {{virtual page name}} variable.
Eg.
function() {
if ({{virtual page name}} == undefined) {
return null;
} else{
return {{virtual page name}};
}
}

This will check if the virtual page name is undefined, if it is it will set the value as null, if not then it sets the correct hard coded virtual page name.

Hopefully this helps,
Omar

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Olgierd N
May 2016

Re: Google Tag Manager - overwrites {{virtual page view}} with {{url hostname}}?

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆
Hi Andrzej,

To fix this you may want to write a custom javascript for the {{virtual page name}} variable.
Eg.
function() {
if ({{virtual page name}} == undefined) {
return null;
} else{
return {{virtual page name}};
}
}

This will check if the virtual page name is undefined, if it is it will set the value as null, if not then it sets the correct hard coded virtual page name.

Hopefully this helps,
Omar

Re: Google Tag Manager - overwrites {{virtual page view}} with {{url hostname}}?

Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆
Thank you Omar for your quick and thorough response. I'll test it right away and let you know if it worked.

BTW. Do you know why it behaved that way in the first place and substituted virtual page name with URL hostname?