Analytics
2.7K members online now
2.7K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Excluding internal traffic with cookies

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello

 

I am trying to filter out our internal traffic from our organization, but using the IP filter in Analytics is not possible since our internet connection from the office uses DHCP and the IP address fluctuates. I have read some articles and have resolved to using the _setCustomVariable()  in the cookie to identify internal traffic as employees. I am having some slight difficulty with that:  we have an online store and a blog. The blog runs in a subfolder on the same domain as the shop, but we are using a different Google Analytics property to track the blog activity.  I am not sure how I could set the cookie custom variable to mark the visitor as an employee for both the shop and the blog and thus both different GA properties. I think the problem lies with the fact that both are actually on the same domain. Or something like that. I am not too terribly experienced with this kind of thing.

 

I have found that the advanced segment does exclude my own traffic from the shop, but not for the blog. So it works halfway.

 

My solution was to create an html file in the root of the domain with the script to set the custom variable, as demonstrated in the articles I've read, and then setup an advanced segment to filter the data. I have included a second snippet of script in that same file, to also set the variable for the blog GA property. I assume the problem is it cannot be done in one html file, or perhaps the "key" cannot be 1 in both scripts...  Please help

 

This is the script I have used:

 

 <!-- Set GA cookie Exclude for Outdoorphoto SHOP GA Account -->
        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-xxxx-1']);
          _gaq.push(['_setCustomVar', 1, 'employee', 'Yes', 1]);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script>
        
        <!-- Set GA cookie Exclude for Outdoorphoto BLOG GA Account -->
        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-xxxx-3']);
          _gaq.push(['_setCustomVar', 1, 'employee', 'Yes', 1]);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script>

Excluding internal traffic with cookies

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

For anyone interested, I have solved this issue myself by using Google Tag Manager to send over a custom dimension which identifies the traffic as coming from an employee.

 

This video by Julian was super helpful:   https://youtu.be/4nT2uFCNv_4

 

 

Excluding internal traffic with cookies

Explorer ✭ ☆ ☆
# 3
Explorer ✭ ☆ ☆

Hi Johan. So you now use google universal and not google classic?

Excluding internal traffic with cookies

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hello.  We have been using universal tracking for a long time now. I realised that the _setCustomVar code that I tried to use initially works with the legacy analytics code. Possibly the reason why it didn't work. But now I have done it in the newest recommended way, by making use of custom dimensions. And I am deploying UA with tag manager.