logo

Δ All posts

Mail Servers in Google Analaytics Traffic Sources

15 June 2010

I got real real tired of mail servers clogging up my Google Analaytics Traffic Sources list. Its getting to the point where over half of them are mail servers. Here's a snapshot if what you probably see:

Obviously, this is caused by people clicking to your site via their webmail. I have a site that emails a lot of comments.

Solution? Sum them all up.

First, create a new subdomain (I used 'mailref.domain.com'), and make sure that all mails link back to this domain. We're going to redirect these users eventually to the content they were looking at, but we place a meta-refresh http redirect tag in their way so they lose their mailserver, as far as Google Analytics tracking code is concerned.

If you are using apache, you can use a reverse proxy to serve up this new intermediary page:


<VirtualHost *:8080>
        ServerName mailref.domain.net
        RequestHeader set Referer "http://mailref.domain.net" early
        ProxyPass / http://domain.net/mailref/
        <Proxy http://domain.net/mailref/>
                Order Allow,Deny
                Allow from all
        </Proxy>
</VirtualHost>

At this point, all you need to do is create a dynamic script at domain.net/mailref/ which will grab the location, since mailref.domain.net/wtvr/ will now call domain.net/mailref/wtvr/. What I do is pass everything after /mailref/ ("wtvr") into my script as a variable.

Then you create a plain html document and pass the redirect variable in:


<html>
        <head>
                <meta http-equiv="refresh" content="0;url=http://domain.net/{{ redirect_url }}" >
        </head>
        <body>
                <h1>You are being redirected to 
                   <a href="http://domain.net/{{ redirect_url }}">http://domain.net/{{ redirect_url }}. 
                   Please feel free to click the link if it does not automatically redirect.</h1>
        </body>
</html>

That's it. Keep in mind if people are linking to an anchored link (domain.net/content#some_anchor) you will need to change this up so you can scarf it in your script. What I do is pass them into the email as a GET variable (anchor="some_anchor") and then build my redirect_url variable manually to include it as an anchor.

Now all your mailtraffic will show up in google analytics as 'mailref.domain.net'!

Comments

dissertation writer says...

mmm interesting facts... I think it is important to know this

Posted at 4:11 p.m. on November 10, 2011

Essays

View all