Is there a way to exclude, from all properties and all views of Google Analytics, the visitors with a specific user agent?
Note: it's not for spam/bot prevention (I already checked the feature Admin > View settings > Bot filtering > Exclude all hits from known bots and spiders), it's to remove a part of own traffic. I can't use IP filtering because my IP changes all the time, and I use many devices (mobile/desktop/laptop). I also can't use cookies, because often I want to test my website as a random non-logged user. I didn't find anything even after exploring deeply the Analytics UI. Maybe this requires API ?
In the first step you have to get the User Agent into Google Analytics. You can do this with the Tag Manager, by creating a custom Javascipt. This can return the User Agent and you can send it to GA with a custom Dimension or a Event. (It´s also possible to do this without the GTM).
Log in to the Tag Manager and navigate to Variables
Now we have to add a Javascript Variable. The User Agent is stored in the navigator.userAgent property
Now we have to push this data into the Google Analytics Account. We could do this with a custom Dimension or a Event. In this example we take a Event. As Action we send the Page Path - you don´t have to do this, but maybe it´s helpfull later for some reports. As a Trigger we define "All Pages" so the event is fired with every pageview. The User Agent we send as a Event Label.
If you have this information in GA you can add a filter on Account Level (for alle Views and Propertys).
Filter Type = Custom > Select the Event or Dimension > Type the User Agent to exclude.
We can see the User Agent of the Users visited our site now in GA Behavior > Events > Top Events > Search for the Event Category (namend in Tag Manager (in our case "User Agent"))
In the last step we exclude the User Agent from all our Propertys and Views.
Admin > All Filters (In the Account column) > "+ Add Filter" > Filter Type = Custom > Exclude > Select "Event Label" in the Dropdown > specify the User Agent to ignore
Select the Views, there this User Agent should be ignored > DONE
Although this doesn't directly answer the question of how to block a user by user-agent string, it does I think solve the problem of how to remove your own personal traffic from being counted by Google Analytics
Google created a chrome plugin:
Google Analytics Opt-out Add-on (by Google)
https://chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh
(Does require a chromium-based browser and appears you're using firefox but may help other users. Interestingly, there does appear to be a link which will download an xpi extension file if accessed from Firefox, but I'm not too sure about it https://tools.google.com/dlpage/gaoptout )
For Firefox, I believe this one can block Google Analytics traffic:
uBlock Origin
https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
(Google Tag Manager seemed a bit labyrinthic for me.)
I finally did this:
Use Custom UserAgent String extension (available for FF and Chrome) and set UserAgent to NoTracking (you can do it specifically for certain websites, i.e. your websites only, see options).
Add this in the PHP page, in the Analytics Javascript part:
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'NoTracking') echo 'if (false)'; ?>
It looks like this:
<script>
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'MyselfXYZ12') echo 'if (false)'; ?>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)}) window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxx-x', 'auto');
ga('send', 'pageview');
<script>
This will have the effect of disabling the creation of ga object for your traffic only.
NB: I first thought about disabling GA code for my own traffic via Javascript with if (navigator.userAgent == 'NoTracking') but it seems that the UserAgent change thanks to the extension "Custom UserAgent String" has effect only after the page is rendered, which is too late.
Related
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
})
})
I have three sites across which I need to track traffic in the same Google Analytics account, with the traffic originating from the first one, passing from the second one, and being converted on the third one.
Site#1 is on domainA.com
Site#2 is on sub1.domainB.com
Site#3 is on sub2.domainB.com
I visit Site#1 (example URL: domainA.com/?utm_source=MySource&utm_medium=MyMedium&utm_campaign=MyCampaign) and I click on the element (button) which takes me to Site#2. The URL then becomes sub1.domainB.com/?_gl=[something]&_ga=[someghing else] which basically indicates that cross domain tracking has been set up correctly, and appears to be working. In Analytics I can see that Source, Medium, and Campaign are the same ones as set in the Site#1 url parameters.
On Site#2 I click on yet another element (a different button) and that takes me to Site#3. That page's url now becomes sub2.domainB.com and there are no CDT url parameters present there, which at first glance seems to be correct, as CDT shouldn't care about subdomains, right?
But then I examine the Google Analytics data, and this is when I get confused; Site#1, and Site#2 both seem to share the same Source, Medium, and Campaign data, as set in the original URL. When I navigate to Site#3 however, and place my order there, I am seeing that the Source, Medium, and Campaign are now (direct), (none), and (none), which indicates that the UTM data is lost somewhere along the way.
My current configuration in GTM is the following:
GTM and Google Analytics fires on all three sites.
Track Type: Page View (Fires on all pages)
Enable overriding settings in this tag (Enabled)
More Settings > Fields to Set > Field Name "allowLinker" : true
More Settings > Fields to Set > Field Name "cookieDomain" : auto
(I've experimented both with and without this field, without much different outcome)
More Settings > Cross Domain Tracking > Auto Link Domains : domainA.com, domainB.com
More Settings > Cross Domain Tracking > Decorate Forms: True
Also, in Google Analytics' Property > JS Tracking Info > Referral Exclusion List, I have both domainA.com, and domainB.com listed there.
What is it that I am missing, that would allow me to make Site#3 be aware of the utm_source, utm_medium, and utm_campaign values when the user eventually converts?
I am not sure of the best way to handle this, however I am sure it is possible to implement with Google Analytics.
I currently have 1 Google Analytics account with all the data.
I would like to create 3 additional "views" within Google Analytics to filter each part of my app accordingly.
The sections are:
the landing pages landing (sales pitch)
the application pages app (the product we offer)
the customer portal pages portal (the product we offer to our user which thier users view).
So dimensions/views (unsure of the terminology here) are;
landing app and portal.
Currently I am using code like the following;
function gtag() {
dataLayer.push(arguments)
}
window.dataLayer = window.dataLayer || [], gtag("js", new Date), gtag("config", "UA-XXXXXXXXX-1", {
custom_map: {
dimension1: "website_segment"
},
website_segment: "landing"
});
I was then expecting to see these values in;
View > Filters > Custom
However they don't exist.
Please note:
I do not wish to utilize separate GA accounts to achieve this.
I cannot utilize the URL scheme with regex to achieve this.
Custom Dimensions should be available in your list of fields when you're setting up a filter for your GA view.
It looks like you're sending info to GA with the code you provided, but have you defined the Custom Dimension in your GA settings? You'll need to do that as a first step.
Access Property > Custom Definitions > Custom Dimensions, add a custom dimension, and set the scope (you'll want a Hit scope for your use case). Then ensure your code is configured to send to the dimension you just created.
See https://support.google.com/analytics/answer/2709828#Lifecycle for an overview of Custom Dimensions - though it looks like the code snippets there are out-of-date, depending on which version of GA you're using.
As far as I understand your need, it absolutely seems feasible. You collect your data in one Analytics property, and you would like to create separate views for various site content, where content is identified by a custom dimension, instead of the page path.
First, make sure, you have enabled custom dimension 1 in your property settings. As you are collecting this data on hit level, you need to set the custom dimension to hit level as well.
Second, you need to deploy your code to send this data to Google Analytics. I assume, you can substitute the proper value (landing/app/portal) for the website_segment key. Please let me know, if this is also part of your question, how to assign the proper value to the defined custom dimension.
To check if data is sent, you can use Google Analytics Debugger Chrome extension, or you can inspect the call to www.google-analytics.com in developer console / Network tab, whether cd1 parameter is set.
To verify if data is available in Google Analytics, the easiest way is to open the Behavior / Content / All pages report, and to add your custom dimension as a secondary dimension for a period, which should already contain data.
Third, you need to create your new views and your filters within Google Analytics. Please note, that you won't see any available values here, but you can still select your custom dimension, and define a filter.
Example: I have 3 sites, a.com, b.com, and c.com. How can I keep track of the traffic that starts out at a.com and ends up at c.com, using Tag Manager and Universal Analytics?
I know that using referral source is an easy enough thing to view in UA, but I really need referral referral source because UA only uses the most recent referrer, not a referrer n sites back.
Please note that this question is not just about cross-domain tracking, rather keeping track of a site visited before the current referral.
Using GTM
If you use GTM (Google Tag Manager), you must create a permanent variable that contains the domains where your site might go to or be visited from.
Lets call it "myDomains". It would be like this:
myDomains : permanent : "a.com,b.com,c.com" (without quotes)
After this, in your pageViews tags, you'll need to set some fields:
In "more configurations", go to "fields to set" add some fields and set the following properties:
Field Name : Value
allowLinker : true
And, if you use multiple sub-domains, add the following:
cookieDomain : auto
Now, still in the "more configurations", under "Cross Domain Tracking", you will use the variable myDomains (that we created before) on the "Auto Link Domains" as this:
{{myDomains}}
Now you just have to save it and now you can track your multiple domains.
Hard-Coded
If You don't use GTM and insert the tags directly to your source code, then what you need is similar to what we did in GTM:
ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['a.com', 'b.com', 'c.com'] );
Note that just like we did in GTM, we:
set the cookieDomain (implicitaly with "auto")
set the field "allowLinker" true
set the "autoLink" to an array of strings, each one containing one of the domains that will send/receive visitors to/from your site.
Note: if you use the same domain but just diferent levels of sub-domains, you will just need to set the cookieDomain to auto, no need for Cross-Domain.
Further reading
Google guide for this implementation
There is no real way to do this within the GA interface.
What you could do is create a new GA property that all these websites send data to (if you haven't already done so).
Then create a filter for this property that appends the hostname to the request URI. You can learn to so this here in the Google documentation. This will allow you to see the full URL thus allowing you see all websites.
I would then create two custom dimensions: sessionId and hitTimeStamp. These can deployed through Google Tag Manager. An article by Simo Ahava found here explains well how to do this.
Using SQL, you will be able to partition page by sessionID and order by hitTimeStamp to give you a view on page flow across each website to c.com.
I do not fully understand your use case, but you can catch the original referrer, store it somewhere (e.g. in a cookie) and then send it e.g. via the url to the following page. Then you catch the query parameter and use it in a set call:
ga('set', 'referrer', '<original referrer>');
ga('send','pageview');
For all hits following the set call GA will record the referrer as the value of ">" which you replace with your captured value.
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()
}