Preventing trackPageView call in GA from GTM - google-analytics

We have many clients that are using Google Analytics (GA) via Google Tag Manager (GTM) on their website. My company provides AJAX pages for our client's site where we track user interaction using custom trackPageView calls. For regular GA code this was not a problem - we would set up the GA code in the static header, omitting the trackpageview call
<script type="text/javascript">
var _gaq=_gaq||[];
_gaq.push(['_setAccount','UA-5620270-1']);
</script>
and then whenever the user interacts with something on the AJAX portion of the page (initial page load, clicking options etc) we call trackPageView with a virtual URL
_gaq.push(['_trackPageview','/someurl?param1=abc&param2=def']);
The problem we have with GTM is that we are getting double tracking - the initial trackPageView call coming from GTM, then the virtual URL call on the AJAX portion of the page - on initial page loads. We can't disable the virtual URL on initial page loads on our end. We need to be able to get GTM to send through all the GA code (setAccount, domain name etc) except for the trackPageView bit. Is there any way to do this in GTM?

Not the most elegant, but easy to implement solutions:
pass a virtual url to the page call in GTM and set up a filter in your data views that excludes this url from the reports or
place your GA code in a custom tag instead of using a code template and omit the trackPageView-Call

I am not sure if this option is possible given your description, but virtual pageviews are not the best solution -- the total pageviews and related metrics are inflated and you cannot tell which segments are really engaging with the site more and which less.
Event tracking would be a smart way to do this. And with new GTM this is not difficult to setup at all. You could create all-new tracking (to the same account) and attach a string to your new tags, and then simply add include-only filter that will not allow any other requests.

Related

How to track link clicks for external sites using Google Tag Manager and G4A?

Let's say I have a landing page URL that is not on my own site, www.notmysite.example/somepage and I want to advertise this link. I would like to create a URL that is tracked through my G4A Tag Manager, whereby the link click, referrer, etc., are all tracked in a G4A campaign.
I found this video that uses the older Universal Analytics and it's looks like a convoluted solution.
Basically, I just want an intermediary link that tracks the click and redirects to the proper page.
Since I do have access to a WordPress site that has G4A tracking, I'm thinking of creating a redirect on that page that reads the URL parameters. However I'd rather not have to deal with another system and configure redirects this way.
How can I accomplish this with G4A and Google Tag Manager?
-- UPDATE --
I'll try to clarify. Given a link like a GoFundMe campaign link, GoFundMe has their own internal tracking and analytics. However, I can't see how to add tracking to that link for my own personal use and/or see analytics on their site. Therefore, I want to create my own link that does the analytics tracking then forwards the user to the desired page.
In following the video I cited above, I was able to create an intermediary link capture but it does require a page on your website, where you can add a brief "loading" image or something.
This solution involves the following steps:
url-redirect_parameter URL variable, where if the "redirect" query key is present, it will fire
Create a redirect CUSTOM JavaScript variable that reads the url-redirect_parameter variable
function() {
try {
return {{url-redirect_parameter}}?setTimeout(function(){window.location='{{url-redirect_parameter}}'},500):false;
}
catch(e) {
return e;
}
}
This custom JS variable references a redirect tag with the following configurations
redirect Trigger trigger that to your GA tag on your website
What this captures now is whenever there is a "redirect=" in the query string, the trigger will fire, record and redirect.
Another solution is just to add UTM parameters to a page you control on your site and have code on that page to auto-redirect to a QS parameter as well. This essentially does just that by injecting JS that does the redirect if the QS is present.
I hope his helps someone else looking for a similar solution and open to other solutions, like a G4A solution.
Here is the Universal Analytics result:
Not quite understand your situation and your goal based on your explation.
But assuming you have back-end access to where you'll be adding the link you wanted to track, you can also track event using google data layer instead of redirects
All you have to do is listen to the click event of the button
e.g.
Click Me
event and datalayer
const link = document.getElementById('track-me')
link.addEventListener('click', function() {
window.dataLayer = window.dataLayer || [] // this should have been already in your script if you are using GA script
dataLayer.push({
'event': 'click',
'time': new Date().toLocaleString(),
'clickFrom': window.location.href,
'referrer': document.referrer
})
})

Track external search form in Google Analytics/GTM

We have a search box on our website that searches a product we subscribe to. It's hosted on the third party's server, not on our domain.
Since it's just embedded on our site, I can't use Google Analtyics' built in configuration for tracking site search.
Is there another way I can track the terms used to search in the form, using either Google Analytics/Tag Manager?
yes, you can use GTM if the search query is entered on your site. Let's say, using a trigger on the search CTA click, you can then use a custom JS variable where you get the value of the search field using JS, use that variable in a GA event tag and there you have your value logged in GA.

Google Tag Manager with ChaplinJS

I am in the process of building a chaplinJS client app and needed capabilities to add google analytics.
I want to use Google Tag Manager (GTM) and added the tracking code to my html file. Then went on over to GTM and setup the PageView event tag.
For some reason none of the page view events after the initial load are trigged. Does GTM work with chaplinJS? I imagine its looking for url change and then pushes out a Universal analytics page view event.
Has anyone else done this? I suppose the other route could be to update application.coffee and listen for "route:match" event and then push out a pageview event. I figured its easier to do this with GTM because I can always add new tags as I go.
Thoughts?
I followed the approach listed here to get my pageView tracking working
http://decompile.it/blog/2013/06/21/integrating-google-tag-manager-and-google-analytics-in-a-single-page-application/
Exactly, throw virtual pageview event on every navigation and that should help getting all pages tracked.
I have used similar handling for my backbone single page application.

Google Analytics referral triggered by a bookmarklet

I have a question regarding Google Analytics and unwanted referral stats generated by a bookmarklet.
I have a web service with GA installed. My users are using a bookmarklet to accomplish a certain task while visiting some other web page. Bookmarklet creates an iframe and opens up a page which is also on my domain and that page contains the same GA code.
For some reason GA sees those web sites (pages that bookmarklet was used on) as referral pages. That creates a problem for me since those pages are not real referrals (no actual links to my site). I have no desire to track pages my users marked with the bookmarklet.
It’s important to mention that bookmarklet page must be a part of the same domain as my main page. I can not move it on other domain or subdomain.
This is what I tried so far:
I’ve created a new GA account (subdomain.mydomain.com) and used it only on my bookmarklet page hoping that all stats related with the bookmarklet will appear on that account. This worked only partially. Stats for the bookmarklet started to appear on the new account but my original GA account continued to track referral pages.
We tried to use a pop up window to load a web page instead of the iframe. No difference.
Any help on how to get rid of unwanted referral sites would be appreciated.
See _setReferrerOveride:
_setReferrerOverride()
_setReferrerOverride(newReferrerUrl)
Sets the referrer URL used to determine campaign tracking values. Use this method to allow gadgets within an iFrame to track referrals correctly. By default, campaign tracking uses the document.referrer property to determine the referrer URL, which is passed in the utmr parameter of the GIF request. However, you can over-ride this parameter with your own value. For example, if you set the new referrer to http://www.google.com/search?hl=en&q=hats, the campaign cookie stores a new campaign with source=google, medium=organic, and keyword=hats.
_gaq.push(['_setReferrerOverride', 'URL-YOU-WANT-AS-REFERRER']);
Or, you could try
_addIgnoredRef():
_addIgnoredRef()
_addIgnoredRef(newIgnoredReferrer)
Excludes a source as a referring site. Use this option when you want to set certain referring links as direct traffic, rather than as referring sites. For example, your company might own another domain that you want to track as direct traffic so that it does not show up on the "Referring Sites" reports. Requests from excluded referrals are still counted in your overall page view count.
Async Snippet (recommended)
_gaq.push(['_addIgnoredRef', 'www.sister-site.com']);
You would have to grab the referrer and populate it dynamically. Probably with parent.document.referrer Of course this might make any referrals (non-bookmarklet) from these sites not record in the future. And, at some point you would need to clear them.
The most simple solution, if you don't need to track the hits from the bookmarklet at all, is to simply not include the GA code in the web page when it is opened by the bookmarklet.
Your bookmarklet can open the page like http://yoursite.com/?mode=bookmarklet
And in your server side code you can use something like
if ( mode != "bookmarklet" ) {
outputGaCode()
}

Google Virtual Pageview Setup

I need some help with the setup of tracking virtual clicks on a submit button. What I need to do is get the referring site, which Google already tracks, and then track if they click on the button. I have setup an onclick for the submit button and setup a goal in Analytics but it is not tracking. I do have the code in place for Analytics in my header to track pageviews.
So what I am trying to do right now with my goal is to track a referring website and then track who clicks on the button. The virtual view I am using for the click is:
onclick="pageTracker._trackPageview('/Orders/Subscription');"
Thank you for any help in getting this setup working. I am still working on learning analytics.
If you want to ...get the referring site, which Google already tracks at the time the user clicks the submit button, you will have to read the cookies (the _utmz in this case) that GA sets and extract it from there.
Referral data can be obtained from the reports in GA, but if you want it at the time of submit, you'll have to get it from the cookies. Plain vanilla javascript can do this for you, just google it. Or, use whatever language your pages are written in to extract the data from the cookie (PHP and many others have this capability).
Regarding tracking the virtual page view, if the user can submit your form by hitting the enter key, then onclick is not desirable. onsubmit in the form tag would be better.
If it is still not recording for you, make sure your goal steps are entered into GA correctly (it's quite common to mess this up and GA is not forgiving to even the slightest error) and that you are using the traditional tracking snippet in the head of your document because your example is in the traditional tracking format. You should not mix async and traditional snippets.
To check if GA is even tracking your virtual page, go to the Content, Top Content report and filter by your virtual page. If it's in there, then it's your goal tracking set up. If it's not in there, it's your virtual page tracking on the form itself.
HTH.

Resources