Solved

JavaScript: Prevent  _gat._getTracker from causing errors

Posted on 2011-03-14
5
483 Views
Last Modified: 2012-05-11
I can I prevent these two lines from causing errors?

var pageTracker = _gat._getTracker("ZW-12345678-9");
pageTracker._trackPageview();

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello World</h1>

<script type="text/javascript">

//// Rows below may be modified
var _gat = {}; 
_gat._getTracker = function() {return 1;}
/// Rows above may be modified

/// I cannot modify code after this point ///
var pageTracker = _gat._getTracker("ZW-12345678-9");
pageTracker._trackPageview();
</script>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
  • 3
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 35133053
For example :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello World</h1>

<script type="text/javascript">

//// Rows below may be modified
	var _gat = new function() {
		this["_getTracker"] = function(s) {
			return this[s];
		}
		this["ZW-12345678-9"] = {}
		this["ZW-12345678-9"]["_trackPageview"] = function() { 
			alert("tracked");
		}
	}

/// Rows above may be modified

/// I cannot modify code after this point ///
var pageTracker = _gat._getTracker("ZW-12345678-9");
pageTracker._trackPageview();
</script>
</body>
</html>

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 35133126
Thanks, only one problem: the value of this is not always ZW-12345678-9
_gat._getTracker("ZW-12345678-9");

It is different on every page and I have no control over its value.  
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35133307
So line 12 to 13, don't worry about which one you're returning, always returnt the value for "ZW-12345678-9" :


this["_getTracker"] = function(s) {
			return this["ZW-12345678-9"];
		}

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35133312
So line 12 to 13, don't worry about which one you're returning, always returnt the object for "ZW-12345678-9"
0
 
LVL 1

Expert Comment

by:JerseyFoo
ID: 35133540
Why are you messing with Google Analytics anyway?  If you're having errors with their code, check to see if they have a new version of their snippet available.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML5 Looping table certain Cell 11 56
Javascript - Uncaught SyntaxError: Unexpected token } (Image Swap onclick) 12 53
Json Schema 8 32
Fix Form size HTML 16 15
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question