jQuery code to track clicks on outgoing links (Google Analytics) -
i found on web:
$('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() { pagetracker._trackpageview('/outgoing/' + $(this).attr('href')); });
but it's not working. in google analytics account there no /outgoing/
links showing (it's been 24+ hours since implemented it).
what's wrong code? i'm using jquery of course ;)
i have:
<script type="text/javascript"> var gajshost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3cscript src='" + gajshost + "google-analytics.com/ga.js' type='text/javascript'%3e%3c/script%3e")); </script> <script type="text/javascript"> try { var pagetracker = _gat._gettracker("ua code"); pagetracker._trackpageview(); } catch(err) {} </script>
try (note double quotes attribute values , not :not()):
$('a[href^="http"]:not([href*="://' + document.domain + '"])').click(function() { pagetracker._trackpageview('/outgoing/' + $(this).attr('href')); });
also, links static (on html page) or dynamic (generated javascript)? if add links after code need call code again attach click event handler.
Comments
Post a Comment