Add Google Analytics Click (event) tracking code to Javascript window.open -


i have following javascript in head :

// google analytics code required eventtracking <script type="text/javascript"> function trackoutboundlink(link, category, action) { try { _gaq.push(['_trackevent', category , action]); } catch(err){} settimeout(function() {document.location.href = link.href; }, 100); }  

and following in body:

// required activate social bookmarks $(".btn_fb").click(function() {     window.open("");     return false; });     $(".btn_tw").click(function() {     window.open("http://twitter.com/home?status=webpage title"+document.url+"", "twitter", "width=660,height=400,scrollbars=no;resizable=no");     return false; });     $(".btn_li").click(function() {     window.open("http://www.linkedin.com/sharearticle?mini=true&amp;url="+document.url+"&amp;title=webpage title;summary=webpage summary", "linkedin", "width=660,height=400,scrollbars=no;resizable=no");     return false; });         $('.btn_go').click(function() {     window.open("http://plus.google.com/share?url="+document.url, 'googleplus', 'width=660,height=500,scrollbars=no,resizable=no');     return false; });  $(".btn_ma").attr("href", "mailto:?subject=webpage subject&body=webpage summary" + window.location);  </script>  //ga code     <script type="text/javascript">           var _gaq = _gaq || [];           _gaq.push(['_setaccount', 'ua-nnnnnn-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> 

and following in html:

      <div class="btn_fb"></div>       <div class="btn_tw"></div>       <div class="btn_li"></div>       <a class="btn_ma"></a>       <div class="btn_go"></div> 

the links function correctly not tags (except .btn_ma) cannot add google analytics event tracking per documentation: https://support.google.com/analytics/answer/1136920?hl=en-gb.

any advice best approach here?

you can add event tracking jquery click events.

// required activate social bookmarks $(".btn_fb").click(function() {     window.open("");     try {      _gaq.push(['_trackevent', "{category}", "{action}"]);      } catch(err){}     return false; });    $(".btn_tw").click(function() {     window.open("http://twitter.com/home?status=webpage title"+document.url+"", "twitter", "width=660,height=400,scrollbars=no;resizable=no");     try {      _gaq.push(['_trackevent', "{category}", "{action}"]);      } catch(err){}     return false; });  $(".btn_li").click(function() {     window.open("http://www.linkedin.com/sharearticle?mini=true&amp;url="+document.url+"&amp;title=webpage title;summary=webpage summary", "linkedin", "width=660,height=400,scrollbars=no;resizable=no");     try {      _gaq.push(['_trackevent', "{category}", "{action}"]);      } catch(err){}     return false; });           $('.btn_go').click(function() {     window.open("http://plus.google.com/share?url="+document.url, 'googleplus', 'width=660,height=500,scrollbars=no,resizable=no');     try {      _gaq.push(['_trackevent', "{category}", "{action}"]);      } catch(err){}     return false; });   $(".btn_ma").click(function() {     window.location = "mailto:?subject=webpage subject&body=webpage summary" + window.location     try {      _gaq.push(['_trackevent', "{category}", "{action}"]);      } catch(err){}     return false; }); 

you'll notice i've added click event tracking each click event, when user clicks on div, action taken, , analytics tracked. edited mailing click event can tracked well. idea using service share this or addthis have analytics built in , can link google analytics well


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -