When the Domain mode is set to "Multiple top-level domains", the Google Analytics module will not track outbound links. After investigation I found out that this is because a small mis-assumption in google_analytics.js. Attached a patch.

Comments

hass’s picture

Status: Needs review » Postponed (maintainer needs more info)

Tests have not failed. You may be wrong here... Can you share your domain and all cross domain names AND one example download link, please?

Please note that a download link that is internal (local domain + all cross domains) is not a outbound link.

mpntod’s picture

Same problem. http://www.menshealthforum.org.uk - cross-domain names kayako.menshealthforum.org.uk and menshealthforum.secure.force.com - example link (apologies for using an Amazon link but we know from our Associates stats that a lot of people have clicked on it - but it's not shown up in Analytics.

mpntod’s picture

I think Steven is right on this one.

If trackDomainMode is 2 then you want to check that the link is not pointing at a cross-domain. If it isn't, then you should record the click.

If trackDomainMode is not 2, then you have already checked that you're not pointing at the same site so you can also record the click.

So that's if trackDomainMode != 2 OR if the link is not pointing at a cross-domain - then record the click.

You could also go with NOT (trackDomainMode = 2 AND pointing at a cross-domain) then go ahead.

I've tweaked the code and my site has started working again.

hass’s picture

I'm not 100% sure, but I think it need to be something like

if (drupalSettings.google_analytics.trackDomainMode != 2 || drupalSettings.google_analytics.trackDomainMode == 2 &&  !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)) {

and we need JS tests added to make sure it will not break again.

mpntod’s picture

I think:

if (drupalSettings.google_analytics.trackDomainMode != 2 || drupalSettings.google_analytics.trackDomainMode == 2 &&  !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)) {

is probably logically identical to

if (drupalSettings.google_analytics.trackDomainMode != 2 || !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)) {

since the second condition would only be evaluated in any case if drupalSettings.google_analytics.trackDomainMode was not !=2 - i.e. if it ==2

hass’s picture

??? The second conditon may become true if the first is false and than it behaves wrong.

mpntod’s picture

True. But by definition if

drupalSettings.google_analytics.trackDomainMode != 2

is false, then

drupalSettings.google_analytics.trackDomainMode == 2

is true, so you don't need to say it.

If it's any reassurance, I've made the suggested change to the code and it's working perfectly on my site! :-)

Martin

hass’s picture

Yes, but !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)) may be true also if drupalSettings.google_analytics.trackDomainMode != 2 is false and this is not correct.

mpntod’s picture

Surely, if

!Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)

this means that the link is not to another cross-domain and we want to record the outbound link?

Isn't it only if

Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains)

that we don't want to record the link (i.e. only when the link is to another cross-domain)?

hass’s picture

If the links points to a crossDomain we do not track manually. This page view will be tracked automatically on the target cross domain page. If the links go to any external domain (not the cross domains) we need to track manually.

mpntod’s picture

Or if Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains) is true "we do not track manually"? If the links go to any external domain (not the cross domains) (i.e. !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains) is true), "we need to track manually"?

hass’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.19 KB

Can you give this patch a try and confirm that it fixes the issue, please? Next release may be one Wednesday.

  • hass committed 7e65c6e on 8.x-2.x
    Issue #2336891: Tracking external links when trackdomainmode is set to...

  • hass committed 18c7768 on
    Issue #2336891: Tracking external links when trackdomainmode is set to...

  • hass committed e98c397 on
    Issue #2336891: Tracking external links when trackdomainmode is set to...
hass’s picture

Status: Needs review » Fixed

Tested it under d8 and worked well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

The last submitted patch, google_analytics_8.x_2.x-fix_trackXdomainbug.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 12: Issue-2336891-Tracking-external-links-when-trackdoma.patch, failed testing.

hass’s picture

Status: Needs work » Closed (fixed)