Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-03-2012, 02:41 PM   PM User | #1
surfbird0713
New Coder

 
Join Date: Jun 2012
Location: South Carolina
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
surfbird0713 is an unknown quantity at this point
Google Analytics JavaScript error

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.

Code:
<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?

Code:
<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>
surfbird0713 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.