Google Product Forums

Re: Trying to update to Asyn code


dianaNashif Jun 25, 2012 9:08 AM
Posted in group: Google Analytics

Categories: Asynchronous Tracking Code Snippet :

Hi Sam.
Yes, I have read that page, but I am not getting it........ big sigh!
 
Right now I have this in the head area but it doesn't seem to be working.

     
<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-30843549-1");
           pageTracker
._trackPageview();
         
} catch(err) {}</script>    


<script type="text/javascript">
         
function recordOutboundLink(link, category, action) {
         
try {
         
var myTracker=_gat._getTrackerByName("UA-30843549-1");
          _gaq
.push(['myTracker._trackEvent', category ,  action ]);
          setTimeout
('document.location = "' + link.href + '"', 100)
         
}catch(err){}
         
}
         
</script>

Page code is like first post
<div id="prc-spacing"><table cellpadding="2" width="100%"><tr>
       
<td valign="top"><img src="/images/preg-icon.png" align="left" style="padding-bottom:10px;"></td>
       
<td valign='top'><a href="<?echo $url;?>" target="_blank" onClick="recordOutboundLink(this, 'Outbound Links', 'PRC-<?print "$prc ($prcCity, $prcState)";?>');return false;"><?echo $prc;?></a><br><?print "$location, $prcState ($prcPhone)";?></td></tr></table>
       
</div>

But should I change the page code to the following to use the _gaq.push?
<div id="prc-spacing"><table cellpadding="2" width="100%"><tr>
       
<td valign="top"><img src="/images/preg-icon.png" align="left" style="padding-bottom:10px;"></td>
       
<td valign='top'><a href="<?echo $url;?>" target="_blank" onClick="_gaq.push([_trackEvent, 'Outbound Links', 'PRC-<?print "$prc ($prcCity, $prcState)";?>']);return false;"><?echo $prc;?></a><br><?print "$location, $prcState ($prcPhone)";?></td></tr></table>
       
</div>

I really appreciate your expertise and helping me get this right,
 
Many many thanks,
 
Diana