Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JavaScript: Prevent  _gat._getTracker from causing errors

Posted on 2011-03-14
5
Medium Priority
?
506 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 83

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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

810 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