...

View Full Version : Google Analytics JavaScript error



surfbird0713
10-03-2012, 03:41 PM
When the page loads with the code below, I get an "Unexpected Identifier" error in the Chrome Debugger console, and I'm not sure why. I copied and pasted the code as provided to me, but there must be some unclosed tag or something?

I'm trying to set up a virtual pageview tag on a modal window that pops up. I'm working in the JSP file that generates the page.


<script type="text/javascript">

$(document).ready(function(){
$('a.online').click(function (e) {
$('#retail-modal').modal();
_gaq.push(['_setAccount', 'UA-33021136-1']);
_gaq.push(['_trackPageview', '/vp/test/retailer links page']);
(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);
})();
return false;

});
});

If I enter the code this way, I don't get any errors and I see the event fire when the modal is opened, but I've been told the second function is necessary. Anyone know whassup with this?


<script type="text/javascript">

$(document).ready(function(){
$('a.online').click(function (e) {
$('#retail-modal').modal();
_gaq.push(['_setAccount', 'UA-33021136-1']);
_gaq.push(['_trackPageview', '/vp/test/retailer links page']);
return false;

});
});

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum