Anicho
Anicho

Reputation: 2667

Dynamic google cross domain javascript broken

I am following this article:

http://www.lunametrics.com/blog/2011/12/01/automatic-cross-domain-tracking-revisited/

which leads me to put the following in my site:

https://github.com/oldbie/xdomain/blob/master/xdomain.js

I have removed the jQuery.noConflict(); and reverted to using $ instead.

When I run the code on my site I get $(link).attr("href") is undefined when it hits:

if($(link).attr("href").indexOf(this)!=-1){

but if you look at the code in the link above it is defined when we do:

var link = $(this); var href = link.attr('href');

Is it being defined correctly? If so then can you see something that is wrong?

You can see the replicated issue here:

http://jsfiddle.net/uZFcU/1/

this html causes the issue:

<a id="manage"><span id="ocPM" class="arrowDo"></span></a>

Upvotes: 0

Views: 284

Answers (1)

jk.
jk.

Reputation: 14435

Is it being defined correctly?

Yes

If so then can you see something that is wrong?

No

Since you didn't show all of your code, I ran the git code in a fiddle. I removed the noConflict(); but that was not necessary. I also commented out the calls to GA functions since they are not defined in the fiddle. Alerts were added to show you where the code is firing.

Look over your code for another error or post all of it here because the git code runs fine:

http://jsfiddle.net/uZFcU/

UPDATE after new info added via comment

In your fiddle from your comment below: http://jsfiddle.net/uZFcU/1/

The HTML line <a id="manage"><span id="ocPM" class="arrowDo"></span></a> has no href attribute. So it's undefined.

The git script listenToClicks function is scanning the page on load in the $(document).ready function. When you have anchors or links like that, you will need to modify the listenToClicks to ignore them.

Change this:

$("a").each(function(index) {

to this:

$("a[href]").each(function(index) {

Updated fiddle: http://jsfiddle.net/uZFcU/8/

Upvotes: 2

Related Questions