Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-09-02 12:06:20 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-09-02 12:06:20 +0400
commit4d184bb5e870e7823526c9d60b2971b682278d6e (patch)
treede54ce6b946b26eec88c1b29f8f46e7ec79ac531 /js
parent097393972e41a5c8a429b6b625cd2bf0b16b178d (diff)
refs #4996 replace relative/absolute href links
Diffstat (limited to 'js')
-rw-r--r--js/piwik.js52
1 files changed, 49 insertions, 3 deletions
diff --git a/js/piwik.js b/js/piwik.js
index 0bdba3b1af..f0516a3f49 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -1615,11 +1615,36 @@ if (typeof Piwik !== 'object') {
return;
}
+ if (0 === (''+ link).indexOf('#')) {
+ return;
+ }
+
if (link !== this.removeDomainIfIsUrl(link)) {
return; // outlink or download?
}
return link;
+ },
+ replaceTargetLink: function (node, url)
+ {
+ var clickNode = this.findTargetNode(node);
+
+ if (!clickNode) {
+ return false;
+ }
+
+ var elementName = clickNode.nodeName.toLowerCase();
+
+ if (elementName !== 'a') {
+ return false;
+ }
+
+ if (clickNode && clickNode.setAttribute) {
+ clickNode.setAttribute('href', url);
+ return true;
+ }
+
+ return false;
}
};
@@ -2700,6 +2725,16 @@ if (typeof Piwik !== 'object') {
return base + url
}
+ function buildTrackingRedirectUrl(url) {
+ if (0 === url.indexOf(configTrackerUrl)) {
+ return url;
+ }
+
+ var redirectUrl = toAbsoluteUrl(url);
+ var request = getRequest('redirecturl=' + redirectUrl + '&c_i=' + url + '&' + buildEventRequest('Content', 'click', url, ''));
+ return configTrackerUrl + (configTrackerUrl.indexOf('?') < 0 ? '?' : '&') + request;
+ }
+
/*
* Log all content pieces
*/
@@ -2713,10 +2748,21 @@ if (typeof Piwik !== 'object') {
}
for (index = 0; index < contentNodes.length; index++) {
+ var internalLink = content.findInternalTargetLink(contentNodes[index]);
+ if (internalLink) {
+ content.replaceTargetLink(contentNodes[index], buildTrackingRedirectUrl(internalLink));
+ }
+
content.addClickEventIfInternalLink(contentNodes[index], function (url) {
- var redirectUrl = toAbsoluteUrl(url);
- var request = getRequest('redirecturl=' + redirectUrl + '&c_i=' + url + '&' + buildEventRequest('Content', 'click', url, ''));
- location.href = configTrackerUrl + (configTrackerUrl.indexOf('?') < 0 ? '?' : '&') + request;
+ var targetUrl = buildTrackingRedirectUrl(internalLink);
+
+ // location.href does not respect target=_blank so we prefer to use this
+ var replaced = content.replaceTargetLink(contentNodes[index], targetUrl);
+
+ if (!replaced) {
+ // fallback to location.href
+ location.href = targetUrl;
+ }
});
}