1

I'm trying to track my email links with Google Analytics, but for some reasons it does not work. Here is my code:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xxxxxx']);
  _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>

and here's the onClick function in page source code:

<a href="mailto:mail@mail.sk" onClick="_gaq.push(['_trackEvent', 'Index','Klik - email','mail@mail.sk']);">mail@mail.sk</a>

I tried same tracking for link on other page and it worked. After I installed GA Debug, I found out that when I'm tracking mailto link, error shows up - Failed to load resource: mailto:mail@mail.sk

Does somebody have any ideas why there is an error and how to fix it? Thanks

JanyC
  • 11
  • 1
  • Just because GA Debug says its an error doesn't actually mean its not tracking. Does the `mailto:` link stop working when this error shows up? Are you getting events tracked in GA? I tried this code and it works fine with GA Debug. – Yahel Dec 20 '10 at 15:38

2 Answers2

0

I am assuming these links will be visible in email clients such as outlook and Gmail. Most, if not all, email clients strip all JavaScript out of email messages before displaying them. If you would like to track email opens and other such information your only option is to use pixel tracking methods.

sousdev
  • 132
  • 2
  • 9
0

Wild guess :

Does adding javascript: before the content of your onClick even solves it ?

<a href="mailto:mail@mail.sk" onClick="javascript:_gaq.push(['_trackEvent', 'Index','Klik - email','mail@mail.sk']);">mail@mail.sk</a>
Gabriel S.
  • 1,961
  • 2
  • 20
  • 30
  • 1
    Not likely to do anything. The only thing adding `javascript:` does is change the execution context from local to global, which only matters for use of the `this` keyword. http://stackoverflow.com/questions/2479557/why-is-it-bad-practice-to-use-links-with-the-javascript-protocol – Yahel Dec 20 '10 at 15:39
  • thanks for the information. I often 'wildguess' wrong anyway :D – Gabriel S. Dec 23 '10 at 16:58