Closed sandykadam closed 3 years ago
We could borrow the approach from the drupal google analytics module:
https://git.drupalcode.org/project/google_analytics/-/blob/8.x-2.x/js/google_analytics.js#L67
else if (drupalSettings.google_analytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
if (drupalSettings.google_analytics.trackDomainMode !== 2 || (drupalSettings.google_analytics.trackDomainMode === 2 && !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains))) {
// External link clicked / No top-level cross domain clicked.
ga('send', {
hitType: 'event',
eventCategory: 'Outbound links',
eventAction: 'Click',
eventLabel: this.href,
transport: 'beacon'
});
}
}
We'd need to:
*.ebi.ac.uk/*
would be considered internal)Aside: I noticed the drupal module uses ga('set', 'transport', 'beacon');
, which might be good for us to use as it offers more robust tracking:
https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits
With #1216 merged - can this be closed now?
@sandykadam + @khawkins98
Works great on local but I found new bug when you click on footer logos European commission or any logo link, there is error
`
ERROR TypeError: Cannot read property 'split' of undefined
at vfGaTrackInteraction (vf-analytics-google.js:328)
at HTMLBodyElement.
`
This looks like it might be a separate issue with a missing getElementsByTagName("img")[0]
in
// is there an inner image?
if (linkName.length == 0 && actedOnItem.getElementsByTagName("img")) {
if (actedOnItem.getElementsByTagName("img")[0]) {
if (actedOnItem.getElementsByTagName("img")[0].hasAttribute("src")) {
linkName = actedOnItem.src.split("/").vfGaLinkLast();
}
}
}
Have moved the above to a new issue. Closing this one.
Currently VF2.0 is not able to track external outbound/outgoing links in GA. So we need to add this feature in current component.