Hi all, I've been searching for hours for an answer to this. I can never get help from the google forums, so thought I'd try here. I wasn't sure whether I should post in pay-per-click or web design, but I figure PPC people have experience with this kind of thing.

I'm trying to get google website optimizer (gwo) cross-domain tracking working with the asynchronous code described here:

My outbound link looks like this:

<a href="http://secure.ultracart.com" onclick="_gaq.push(['_link', 'http://secure.ultracart.com']); return false;">link</a>

But when I click on that outbound link, it doesn't go to the other website. It works if I remove the return false; but that stops the gwo conversion from registering.

I thought it might be a javascript conflict, so I made this simple test file, and it still doesn't work:

Is there someone here familiar with gwo who knows what the problem might be? If you look at the page source of my test.php, I think the code is perfect. Thanks very much for any advice you can give me.

Phil

Dani AI

Generated

Short summary and likely cause (for and )
The behaviour you describe — the anchor not navigating when return false is present — is exactly what return false does: it prevents the browser’s default navigation. The GA/Website‑Optimizer _link call is supposed to append the tracker cookies to the URL and then cause navigation, but that only works reliably if the tracker code is loaded, configured to allow the linker, and the destination will accept the linker parameters. (stackoverflow.com)

What to check first

  • Confirm both source and destination pages have the same tracking property and that cross‑domain linking is enabled (allowLinker / _setAllowLinker) on the source and the destination is set to accept incoming linker params. (tourcms.com)
  • Verify the GWO/Control script and the GA snippet are present and in the right order on the pages that participate in the experiment (control script → GA snippet → any page logic).
  • Watch the browser: click the link and inspect the address bar / Network tab to see whether GA parameters are appended and whether a redirect (HTTP→HTTPS) strips them. Redirects or server rewrite rules that remove query strings will break the linker.

A reliable, low‑risk implementation
Rather than relying on an inline onclick + return false, decorate links on page load so the anchor already contains the linker parameters. Example pattern (adapt to your setup — this avoids cancelling the default click):

<script>
_gaq.push(function(){
  var tracker = (_gat && _gat._getTrackers && _gat._getTrackers()[0]) || (_gat && _gat._getTrackerByName && _gat._getTrackerByName());
  if (!tracker) return;
  var els = document.querySelectorAll('a[data-crossdomain]');
  for (var i=0;i<els.length;i++){
    els[i].href = tracker._getLinkerUrl(els[i].href);
  }
});
</script>

This technique decorates links ahead of the click (TourCMS/StackOverflow show the same approach for iframes/links). If you must keep an onclick handler, use a safe fallback: either a short timeout navigation fallback or (with analytics.js / ga) a hitCallback so navigation happens after the hit completes. Always build a timeout fallback so users aren’t stuck if GA is blocked. (tourcms.com)

Final notes
If after the above the destination still doesn’t record conversions, verify the destination actually receives the linker parameters (check the final URL), and confirm the conversion page runs the expected tracking/GWO code to accept and write the incoming cookie. Also be aware ga.js/GWO are legacy-era approaches; modern cross‑domain setups use the linker plugin / gtag/GA4 workflows — migrate if you can. (developers.google.com)

Recommended Answers

All 5 Replies

Hi Phil,

Unfortunately I have absolutely no experience at all with Website Optimizer, so I probably can't be of much help. However, I noticed that http://secure.ultracart.com automatically redirects to https://secure.ultracart.com. I'm wondering if the cross-domain thing doesn't work when switching from the http protocol to https?

Have you tried to see if the link works when only unsecured pages are involved? Just something to rule out.

Have you tried to see if the link works when only unsecured pages are involved? Just something to rule out.

Thanks so much for the idea, but it doesn't seem to matter what I use for a url.

Does all the code work fine when it's all on the same domain?

I didn't notice the Control Script on your test page mentioned in the documentation page you linked to.

Does all the code work fine when it's all on the same domain?

I didn't notice the Control Script on your test page mentioned in the documentation page you linked to.

The control script is there, right at the top. "<script> _udn = "none"; </script>"

Yes, I've never had any problem with scripts when they're on the same domain. The problem is that the "return false" on my link is causing the link to not work. I believe that is what "return false" is designed to do, but I think I read somewhere that the "_gaq.push();" is supposed to counteract it, to allow the link to work.

The control script is what is below the _udn = "none"; line. I'm really not sure though :( I don't know what else to suggest to you, your code does look just like the sample.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.