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
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-09-14 19:05:25 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-09-14 19:05:25 +0400
commite127384e57c076a96462da2f984919abadbcb85e (patch)
tree6b4847bdff5a7c1d4d0c9f14d5da0f2e81f6ce7b
parent78f9254cc62af38e7fdb2725bb32f71c2f766168 (diff)
refs #4996 we have to add build a fully qualified URL of the content piece in case we detect the URL of an image, video or audio, pdf, ... automatically. Otherwise we cannot display a preview in the UI and one would not know which URL was actually meant. Thinking about using //domain/path instead of http://domain/path as it would track different content pieces for http and https otherwise
-rw-r--r--js/piwik.js2
-rw-r--r--misc/internal-docs/content-tracking.md22
-rw-r--r--piwik.js2
-rw-r--r--tests/javascript/index.php141
4 files changed, 107 insertions, 60 deletions
diff --git a/js/piwik.js b/js/piwik.js
index 5072c4ef5d..b375e1a70f 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -1703,7 +1703,7 @@ if (typeof Piwik !== 'object') {
var media = this.findMediaUrlInNode(contentNode);
if (media) {
- return media;
+ return this.toAbsoluteUrl(media);
}
},
findContentTarget: function (node)
diff --git a/misc/internal-docs/content-tracking.md b/misc/internal-docs/content-tracking.md
index d2174492e2..186d8345d1 100644
--- a/misc/internal-docs/content-tracking.md
+++ b/misc/internal-docs/content-tracking.md
@@ -38,13 +38,13 @@ You can use either the attribute `data-track-content` or the CSS class `piwikTra
Examples:
```
<img src="img-en.jpg" data-track-content/>
-// content name = img-en.jpg
-// content piece = img-en.jpg
+// content name = absolutePath(img-en.jpg)
+// content piece = absoluteUrl(img-en.jpg)
// content target = ""
<img src="img-en.jpg" class="piwikTrackContent"/>
-// content name = img-en.jpg
-// content piece = img-en.jpg
+// content name = absolutePath(img-en.jpg)
+// content piece = absoluteUrl(img-en.jpg)
// content target = ""
```
@@ -61,7 +61,7 @@ If we do not find any specific content piece element, we will use the content bl
### How do we detect the content piece?
* The simplest scenario is to provide an HTML attribute `data-content-piece="foo"` including a value anywhere within the content block or in the content block element itself.
-* If there is no such attribute we will check whether the content piece element is a media (audio, video, image) and we will try to detect the URL to the media automatically. For instance using the `src` attribute.
+* If there is no such attribute we will check whether the content piece element is a media (audio, video, image) and we will try to detect the URL to the media automatically. For instance using the `src` attribute. If a found media URL does not include a domain or is not an absolute URL we will make sure to have a fully qualified URL.
* In case of video and audio elements, when there are multiple sources defined, we will choose the URL of the first source
* If we haven't found anything we will fall back to use the value "Unknown". In such a case you should set the attribute `data-content-piece` telling us explicitly what the content is.
@@ -78,8 +78,8 @@ This time we can also automatically detect the content target since we have set
```
<a href="http://www.example.com" data-track-content><img src="img-en.jpg" data-content-piece/></a>
<a href="http://www.example.com" data-track-content><img src="img-en.jpg" class="piwikContentPiece"/></a>
-// content name = img-en.jpg
-// content piece = img-en.jpg
+// content name = absolutePath(img-en.jpg)
+// content piece = absoluteUrl(img-en.jpg)
// content target = http://www.example.com
```
@@ -119,7 +119,7 @@ Examples:
```
<img src="img-en.jpg" data-track-content data-content-name="Image1"/>
// content name = Image1
-// content piece = img-en.jpg
+// content piece = absoluteUrl(img-en.jpg)
// content target = ""
```
@@ -127,8 +127,8 @@ This example would be the way to go by defining a `data-content-name` attribute
```
<img src="img-en.jpg" data-track-content/>
-// content name = img-en.jpg
-// content piece = img-en.jpg
+// content name = absolutePath(img-en.jpg)
+// content piece = absoluteUrl(img-en.jpg)
// content target = ""
```
@@ -432,12 +432,12 @@ Nothing special here I think. We would probably automatically detect the type of
* Would content impressions be tracked in overlay session?
* Overlay session should not trigger a content impression
* Cache allowed site urls for redirects
-* Run JS tests ms phone
* Show images on hover in report
* When a user clicks on an interaction, we should check whether we have already tracked the impression as the content is visible now. If not tracked before, we should track the impression as well
* There can be a scroll or timer event that detects the same content became visible as well. This would not be a problem since we do not track same content block twice
* Maybe v2
* Content piece undefined vs Unknown?
+* Make JS tests work if piwik is installed in a path such as localhost/piwik
## V2:
* "note: as a user, I see that piwik.php redirects is the default "click tracking" solution, but I want to be able to disable this piwik.php redirect and instead use the link tracking 500ms solution."
diff --git a/piwik.js b/piwik.js
index d575e34af2..842d4ada10 100644
--- a/piwik.js
+++ b/piwik.js
@@ -22,7 +22,7 @@ break;case 3:ap=am.charCodeAt(X-3)<<24|am.charCodeAt(X-2)<<16|am.charCodeAt(X-1)
}if(this.hasNodeAttribute(Y,X)){return Y}var W=this.findNodesHavingAttribute(Y,X);if(W&&W.length){return W[0]}},findFirstNodeHavingAttributeWithValue:function(Z,Y){if(!Z||!Y){return}if(this.hasNodeAttributeWithValue(Z,Y)){return Z}var W=this.findNodesHavingAttribute(Z,Y);if(!W||!W.length){return}var X;for(X=0;X<W.length;X++){if(this.getAttributeValueFromNode(W[X],Y)){return W[X]}}},findNodesHavingCssClass:function(aa,Z,W){if(!W){W=[]}if(!aa||!Z){return W}if(aa.getElementsByClassName){var ab=aa.getElementsByClassName(Z);return this.htmlCollectionToArray(ab)}var Y=C(aa);if(!Y||!Y.length){return[]}var X,ac;for(X=0;X<Y.length;X++){ac=Y[X];if(this.hasNodeCssClass(ac,Z)){W.push(ac)}W=this.findNodesHavingCssClass(ac,Z,W)}return W},findFirstNodeHavingClass:function(Y,X){if(!Y||!X){return}if(this.hasNodeCssClass(Y,X)){return Y}var W=this.findNodesHavingCssClass(Y,X);if(W&&W.length){return W[0]}},isLinkElement:function(X){if(!X){return false}var W=String(X.nodeName).toLowerCase();var Z=["a","area"];
var Y=z(Z,W);return Y!==-1},setAnyAttribute:function(X,W,Y){if(!X||!W){return}if(X.setAttribute){X.setAttribute(W,Y)}else{X[W]=Y}}};var m={CONTENT_ATTR:"data-track-content",CONTENT_CLASS:"piwikTrackContent",CONTENT_NAME_ATTR:"data-content-name",CONTENT_PIECE_ATTR:"data-content-piece",CONTENT_PIECE_CLASS:"piwikContentPiece",CONTENT_TARGET_ATTR:"data-content-target",CONTENT_TARGET_CLASS:"piwikContentTarget",CONTENT_IGNOREINTERACTION_ATTR:"data-content-ignoreinteraction",CONTENT_IGNOREINTERACTION_CLASS:"piwikContentIgnoreInteraction",location:undefined,findContentNodes:function(){var X="."+this.CONTENT_CLASS;var W="["+this.CONTENT_ATTR+"]";var Y=Q.findMultiple([X,W]);return Y},findContentNodesWithinNode:function(Z){if(!Z){return[]}var X=Q.findNodesHavingCssClass(Z,this.CONTENT_CLASS);var W=Q.findNodesHavingAttribute(Z,this.CONTENT_ATTR);if(W&&W.length){var Y;for(Y=0;Y<W.length;Y++){X.push(W[Y])}}if(Q.hasNodeAttribute(Z,this.CONTENT_ATTR)){X.push(Z)}else{if(Q.hasNodeCssClass(Z,this.CONTENT_CLASS)){X.push(Z)
}}X=Q.makeNodesUnique(X);return X},findParentContentNode:function(X){if(!X){return}var Y=X;var W=0;while(Y&&Y!==u&&Y.parentNode){if(Q.hasNodeAttribute(Y,this.CONTENT_ATTR)){return Y}if(Q.hasNodeCssClass(Y,this.CONTENT_CLASS)){return Y}Y=Y.parentNode;if(W>1000){break}W++}},findPieceNode:function(X){var W;W=Q.findFirstNodeHavingAttribute(X,this.CONTENT_PIECE_ATTR);if(!W){W=Q.findFirstNodeHavingClass(X,this.CONTENT_PIECE_CLASS)}if(W){return W}return X},findTargetNodeNoDefault:function(W){if(!W){return}var X=Q.findFirstNodeHavingAttributeWithValue(W,this.CONTENT_TARGET_ATTR);if(X){return X}X=Q.findFirstNodeHavingAttribute(W,this.CONTENT_TARGET_ATTR);if(X){return X}X=Q.findFirstNodeHavingClass(W,this.CONTENT_TARGET_CLASS);if(X){return X}},findTargetNode:function(W){var X=this.findTargetNodeNoDefault(W);if(X){return X}return W},findContentName:function(X){if(!X){return}var aa=Q.findFirstNodeHavingAttributeWithValue(X,this.CONTENT_NAME_ATTR);if(aa){return Q.getAttributeValueFromNode(aa,this.CONTENT_NAME_ATTR)
-}var W=this.findContentPiece(X);if(W){return this.removeDomainIfIsInLink(W)}if(Q.hasNodeAttributeWithValue(X,"title")){return Q.getAttributeValueFromNode(X,"title")}var Y=this.findPieceNode(X);if(Q.hasNodeAttributeWithValue(Y,"title")){return Q.getAttributeValueFromNode(Y,"title")}var Z=this.findTargetNode(X);if(Q.hasNodeAttributeWithValue(Z,"title")){return Q.getAttributeValueFromNode(Z,"title")}},findContentPiece:function(X){if(!X){return}var Z=Q.findFirstNodeHavingAttributeWithValue(X,this.CONTENT_PIECE_ATTR);if(Z){return Q.getAttributeValueFromNode(Z,this.CONTENT_PIECE_ATTR)}var W=this.findPieceNode(X);var Y=this.findMediaUrlInNode(W);if(Y){return Y}},findContentTarget:function(Y){if(!Y){return}var Z=this.findTargetNode(Y);if(Q.hasNodeAttributeWithValue(Z,this.CONTENT_TARGET_ATTR)){return Q.getAttributeValueFromNode(Z,this.CONTENT_TARGET_ATTR)}var X;if(Q.hasNodeAttributeWithValue(Z,"href")){X=Q.getAttributeValueFromNode(Z,"href");return this.toAbsoluteUrl(X)}var W=this.findPieceNode(Y);
+}var W=this.findContentPiece(X);if(W){return this.removeDomainIfIsInLink(W)}if(Q.hasNodeAttributeWithValue(X,"title")){return Q.getAttributeValueFromNode(X,"title")}var Y=this.findPieceNode(X);if(Q.hasNodeAttributeWithValue(Y,"title")){return Q.getAttributeValueFromNode(Y,"title")}var Z=this.findTargetNode(X);if(Q.hasNodeAttributeWithValue(Z,"title")){return Q.getAttributeValueFromNode(Z,"title")}},findContentPiece:function(X){if(!X){return}var Z=Q.findFirstNodeHavingAttributeWithValue(X,this.CONTENT_PIECE_ATTR);if(Z){return Q.getAttributeValueFromNode(Z,this.CONTENT_PIECE_ATTR)}var W=this.findPieceNode(X);var Y=this.findMediaUrlInNode(W);if(Y){return this.toAbsoluteUrl(Y)}},findContentTarget:function(Y){if(!Y){return}var Z=this.findTargetNode(Y);if(Q.hasNodeAttributeWithValue(Z,this.CONTENT_TARGET_ATTR)){return Q.getAttributeValueFromNode(Z,this.CONTENT_TARGET_ATTR)}var X;if(Q.hasNodeAttributeWithValue(Z,"href")){X=Q.getAttributeValueFromNode(Z,"href");return this.toAbsoluteUrl(X)}var W=this.findPieceNode(Y);
if(Q.hasNodeAttributeWithValue(W,"href")){X=Q.getAttributeValueFromNode(W,"href");return this.toAbsoluteUrl(X)}},isSameDomain:function(W){if(!W||!W.indexOf){return false}if(0===W.indexOf(this.getLocation().origin)){return true}var X=W.indexOf(this.getLocation().host);if(8>=X&&0<=X){return true}return false},removeDomainIfIsInLink:function(Y){var X="^https?://[^/]+";var W="^.*//[^/]+";if(Y&&Y.search&&-1!==Y.search(new RegExp(X))&&this.isSameDomain(Y)){Y=Y.replace(new RegExp(W),"");if(!Y){Y="/"}}return Y},findMediaUrlInNode:function(aa){if(!aa){return}var Y=["img","embed","video","audio"];var W=aa.nodeName.toLowerCase();if(-1!==z(Y,W)&&Q.findFirstNodeHavingAttributeWithValue(aa,"src")){var Z=Q.findFirstNodeHavingAttributeWithValue(aa,"src");return Q.getAttributeValueFromNode(Z,"src")}if(W==="object"&&Q.hasNodeAttributeWithValue(aa,"data")){return Q.getAttributeValueFromNode(aa,"data")}if(W==="object"){var ab=Q.findNodesByTagName(aa,"param");if(ab&&ab.length){var X;for(X=0;X<ab.length;X++){if("movie"===Q.getAttributeValueFromNode(ab[X],"name")&&Q.hasNodeAttributeWithValue(ab[X],"value")){return Q.getAttributeValueFromNode(ab[X],"value")
}}}var ac=Q.findNodesByTagName(aa,"embed");if(ac&&ac.length){return this.findMediaUrlInNode(ac[0])}}},trim:function(W){if(W&&String(W)===W){return W.replace(/^\s+|\s+$/g,"")}return W},isOrWasNodeInViewport:function(ab){if(!ab||!ab.getBoundingClientRect||ab.nodeType!==1){return true}var aa=ab.getBoundingClientRect();var Z=u.documentElement||{};var Y=aa.top<0;if(Y&&ab.offsetTop){Y=(ab.offsetTop+aa.height)>0}var X=Z.clientWidth;if(G.innerWidth&&X>G.innerWidth){X=G.innerWidth}var W=Z.clientHeight;if(G.innerHeight&&W>G.innerHeight){W=G.innerHeight}return((aa.bottom>0||Y)&&aa.right>0&&aa.left<X&&((aa.top<W)||Y))},isNodeVisible:function(X){var W=g(X);var Y=this.isOrWasNodeInViewport(X);return W&&Y},buildInteractionRequestParams:function(W,X,Y,Z){var aa="";if(W){aa+="c_i="+l(W)}if(X){if(aa){aa+="&"}aa+="c_n="+l(X)}if(Y){if(aa){aa+="&"}aa+="c_p="+l(Y)}if(Z){if(aa){aa+="&"}aa+="c_t="+l(Z)}return aa},buildImpressionRequestParams:function(W,X,Y){var Z="c_n="+l(W)+"&c_p="+l(X);if(Y){Z+="&c_t="+l(Y)}return Z
},buildContentBlock:function(Y){if(!Y){return}var W=this.findContentName(Y);var X=this.findContentPiece(Y);var Z=this.findContentTarget(Y);W=this.trim(W);X=this.trim(X);Z=this.trim(Z);return{name:W||"Unknown",piece:X||"Unknown",target:Z||""}},collectContent:function(Z){if(!Z||!Z.length){return[]}var Y=[];var W,X;for(W=0;W<Z.length;W++){X=this.buildContentBlock(Z[W]);if(w(X)){Y.push(X)}}return Y},setLocation:function(W){this.location=W},getLocation:function(){var W=this.location||G.location;if(!W.origin){W.origin=W.protocol+"//"+W.hostname+(W.port?":"+W.port:"")}return W},toAbsoluteUrl:function(X){if((!X||String(X)!==X)&&X!==""){return X}if(""===X){return this.getLocation().href}if(X.search(/^\/\//)!==-1){return this.getLocation().protocol+X}if(X.search(/:\/\//)!==-1){return X}if(0===X.indexOf("#")){return this.getLocation().origin+this.getLocation().pathname+X}if(0===X.indexOf("?")){return this.getLocation().origin+this.getLocation().pathname+X}if(0===X.search("^[a-zA-Z]{2,11}:")){return X
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index 2de46c4410..0c8a7f6293 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -153,6 +153,41 @@ function _s(selector) { // select node within content test scope
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
+ function toAbsoluteUrl(url, encoded)
+ {
+ var origin = getOrigin();
+ var path = origin;
+
+ if (0 !== url.indexOf('/')) {
+ path += '/tests/javascript/';
+ }
+
+ var absoluteUrl = path + url;
+
+ if (encoded) {
+ return window.encodeURIComponent(absoluteUrl);
+ }
+
+ return absoluteUrl;
+ }
+
+ function toAbsolutePath(url, encoded)
+ {
+ var path = '';
+
+ if (0 !== url.indexOf('/')) {
+ path += '/tests/javascript/';
+ }
+
+ var absolutePath = path + url;
+
+ if (encoded) {
+ return window.encodeURIComponent(absolutePath);
+ }
+
+ return absolutePath;
+ }
+
function loadJash() {
var jashDiv = _e('jashDiv');
@@ -1428,17 +1463,18 @@ function PiwikTest() {
var origin = getOrigin();
var host = location.host;
+ var path = origin + '/tests/javascript';
assertFoundContent(undefined, undefined, undefined, undefined, 'No node set');
- assertFoundContent('ex1', 'img-en.jpg', 'img-en.jpg', undefined);
- assertFoundContent('ex2', 'img-en.jpg', 'img-en.jpg', undefined);
+ assertFoundContent('ex1', toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), undefined);
+ assertFoundContent('ex2', toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), undefined);
assertFoundContent('ex3', 'img.jpg', 'img.jpg', 'http://www.example.com');
- assertFoundContent('ex4', 'img-en.jpg', 'img-en.jpg', 'http://www.example.com');
- assertFoundContent('ex5', 'img-en.jpg', 'img-en.jpg', 'http://www.example.com');
+ assertFoundContent('ex4', toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), 'http://www.example.com');
+ assertFoundContent('ex5', toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), 'http://www.example.com');
assertFoundContent('ex6', undefined, undefined, 'http://www.example.com');
assertFoundContent('ex7', undefined, undefined, 'http://www.example.com');
assertFoundContent('ex8', 'My content', 'My content', 'http://www.example.com');
- assertFoundContent('ex9', 'Image1', 'img-en.jpg', undefined);
+ assertFoundContent('ex9', 'Image1', toAbsoluteUrl('img-en.jpg'), undefined);
assertFoundContent('ex10', 'http://www.example.com/path/img-en.jpg', 'http://www.example.com/path/img-en.jpg', undefined);
assertFoundContent('ex11', undefined, undefined, 'http://www.example.com');
assertFoundContent('ex12', 'Block Title', undefined, 'http://www.example.com');
@@ -1472,17 +1508,17 @@ function PiwikTest() {
assertFoundContent('ex26', 'My Ad', undefined, 'http://fallback.example.com');
assertFoundContent('ex27', 'My Ad', undefined, origin + '/test');
assertFoundContent('ex28', 'My Ad', undefined, origin + '/tests/javascript/test');
- assertFoundContent('ex29', 'My Video', 'movie.mp4', 'videoplayer');
- assertFoundContent('ex30', 'audio.ogg', 'audio.ogg', 'audioplayer');
+ assertFoundContent('ex29', 'My Video', toAbsoluteUrl('movie.mp4'), 'videoplayer');
+ assertFoundContent('ex30', toAbsolutePath('audio.ogg'), toAbsoluteUrl('audio.ogg'), 'audioplayer');
assertFoundContent('ex31', ' name ', ' pie ce ', ' targ et ', 'Should not trim');
ok('test buildContentBlock(node)');
strictEqual(content.buildContentBlock(), undefined, 'no node set');
assertBuiltContent('ex31', 'name', 'pie ce', 'targ et', 'Should trim values');
- assertBuiltContent('ex30', 'audio.ogg', 'audio.ogg', 'audioplayer', 'All values set');
+ assertBuiltContent('ex30', toAbsolutePath('audio.ogg'), toAbsoluteUrl('audio.ogg'), 'audioplayer', 'All values set');
assertBuiltContent(_e('div1'), 'Unknown', 'Unknown', '', 'It is not a content block, so should use defaults');
- assertBuiltContent('ex1', 'img-en.jpg', 'img-en.jpg', '', 'Should use default for target');
+ assertBuiltContent('ex1', toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), '', 'Should use default for target');
assertBuiltContent('ex12', 'Block Title', 'Unknown', 'http://www.example.com', 'Should use default for piece');
assertBuiltContent('ex15', 'Unknown', 'Unknown', 'http://attr.example.com', 'Should use default for name and piece');
@@ -1492,9 +1528,9 @@ function PiwikTest() {
var expected = [
buildContentStruct('name', 'pie ce', 'targ et'),
- buildContentStruct('audio.ogg', 'audio.ogg', 'audioplayer'),
+ buildContentStruct(toAbsolutePath('audio.ogg'), toAbsoluteUrl('audio.ogg'), 'audioplayer'),
buildContentStruct('Unknown', 'Unknown', ''),
- buildContentStruct('img-en.jpg', 'img-en.jpg', ''),
+ buildContentStruct(toAbsolutePath('img-en.jpg'), toAbsoluteUrl('img-en.jpg'), ''),
buildContentStruct('Block Title', 'Unknown', 'http://www.example.com'),
buildContentStruct('Unknown', 'Unknown', 'http://attr.example.com'),
];
@@ -1633,25 +1669,25 @@ function PiwikTest() {
strictEqual(actual, undefined, 'appendContentInteractionToRequestIfPossible, the content block node was clicked but it is not the target');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex104'));
- strictEqual(actual, 'c_n=img.jpg&c_p=img.jpg', 'appendContentInteractionToRequestIfPossible, the actual target node was clicked');
+ strictEqual(actual, 'c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true), 'appendContentInteractionToRequestIfPossible, the actual target node was clicked');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex104'), 'clicki');
- strictEqual(actual, 'c_i=clicki&c_n=img.jpg&c_p=img.jpg', 'appendContentInteractionToRequestIfPossible, with interaction');
+ strictEqual(actual, 'c_i=clicki&c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true), 'appendContentInteractionToRequestIfPossible, with interaction');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex104_inner'));
- strictEqual(actual, 'c_n=img.jpg&c_p=img.jpg', 'appendContentInteractionToRequestIfPossible, block node is target node and any node within it was clicked which is good, we build a request');
+ strictEqual(actual, 'c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true), 'appendContentInteractionToRequestIfPossible, block node is target node and any node within it was clicked which is good, we build a request');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex104_inner'));
- strictEqual(actual, 'c_n=img.jpg&c_p=img.jpg', 'appendContentInteractionToRequestIfPossible, a node within a target node was clicked which is googd');
+ strictEqual(actual, 'c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true), 'appendContentInteractionToRequestIfPossible, a node within a target node was clicked which is googd');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex105_target'));
- strictEqual(actual, 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fwww.example.com', 'appendContentInteractionToRequestIfPossible, target node was clicked which is good');
+ strictEqual(actual, 'c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true) + '&c_t=http%3A%2F%2Fwww.example.com', 'appendContentInteractionToRequestIfPossible, target node was clicked which is good');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex105_withinTarget'));
- strictEqual(actual, 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fwww.example.com', 'appendContentInteractionToRequestIfPossible, a node within target node was clicked which is googd');
+ strictEqual(actual, 'c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true) + '&c_t=http%3A%2F%2Fwww.example.com', 'appendContentInteractionToRequestIfPossible, a node within target node was clicked which is googd');
actual = tracker.appendContentInteractionToRequestIfPossible(_s('#ex104_inner'), 'click', 'fallbacktarget');
- strictEqual(actual, 'c_i=click&c_n=img.jpg&c_p=img.jpg&c_t=fallbacktarget', 'appendContentInteractionToRequestIfPossible, if no target found we can specify a default target');
+ strictEqual(actual, 'c_i=click&c_n=' + toAbsolutePath('img.jpg', true) + '&c_p=' + toAbsoluteUrl('img.jpg', true) + '&c_t=fallbacktarget', 'appendContentInteractionToRequestIfPossible, if no target found we can specify a default target');
@@ -1760,12 +1796,12 @@ function PiwikTest() {
tracker.clearTrackedContentImpressions();
actual = tracker.getContentImpressionsRequestsFromNodes([_s('#ex1'), _s('#ex2')]);
strictEqual(actual.length, 1, 'getContentImpressionsRequestsFromNodes, should ignore a duplicated node that has same content');
- assertTrackingRequest(actual[0], 'c_n=img-en.jpg&c_p=img-en.jpg');
+ assertTrackingRequest(actual[0], 'c_n=' + toAbsolutePath('img-en.jpg', true) + '&c_p=' + toAbsoluteUrl('img-en.jpg', true));
tracker.clearTrackedContentImpressions();
actual = tracker.getContentImpressionsRequestsFromNodes([_s('#ex1'), undefined, _s('#ex2'), _s('#ex8'), _s('#ex19')]);
strictEqual(actual.length, 3, 'getContentImpressionsRequestsFromNodes, should only build requests for nodes that are content nodes');
- assertTrackingRequest(actual[0], 'c_n=img-en.jpg&c_p=img-en.jpg');
+ assertTrackingRequest(actual[0], 'c_n=' + toAbsolutePath('img-en.jpg', true) + '&c_p=' + toAbsoluteUrl('img-en.jpg', true));
assertTrackingRequest(actual[1], 'c_n=My%20content&c_p=My%20content&c_t=http%3A%2F%2Fwww.example.com');
assertTrackingRequest(actual[2], 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fad.example.com');
@@ -1785,13 +1821,13 @@ function PiwikTest() {
tracker.clearTrackedContentImpressions();
actual = tracker.getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet([_s('#ex115'),_s('#ex115'), _s('#ex116_hidden')]);
strictEqual(actual.length, 1, 'getVisibleImpressions, should not ignore the found requests but the visible ones, should not add the same one twice');
- assertTrackingRequest(actual[0], 'c_n=img115.jpg&c_p=img115.jpg&c_t=http%3A%2F%2Fwww.example.com');
+ assertTrackingRequest(actual[0], 'c_n=' + toAbsolutePath('img115.jpg', true) + '&c_p=' + toAbsoluteUrl('img115.jpg', true) + '&c_t=http%3A%2F%2Fwww.example.com');
_s('#ex115').scrollIntoView(true);
tracker.clearTrackedContentImpressions();
actual = tracker.getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet([_s('#ex116_hidden'), _s('#ex116_hidden'), _s('#ex115'),_s('#ex115')]);
strictEqual(actual.length, 1, 'getVisibleImpressions, two hidden ones before a visible ones to make sure removing hidden content block from array works and does not ignore one');
- assertTrackingRequest(actual[0], 'c_n=img115.jpg&c_p=img115.jpg&c_t=http%3A%2F%2Fwww.example.com');
+ assertTrackingRequest(actual[0], 'c_n=' + toAbsolutePath('img115.jpg', true) + '&c_p=' + toAbsoluteUrl('img115.jpg', true) + '&c_t=http%3A%2F%2Fwww.example.com');
ok('test replaceHrefIfInternalLink()')
@@ -2933,8 +2969,8 @@ if ($sqlite) {
var contentBlocks = [
null,
{
- "name": "img1-en.jpg",
- "piece": "img1-en.jpg",
+ "name": toAbsolutePath("img1-en.jpg"),
+ "piece": toAbsoluteUrl("img1-en.jpg"),
"target": ""
},
{
@@ -2943,8 +2979,8 @@ if ($sqlite) {
"target": "http://img2.example.com"
},
{
- "name": "img3-en.jpg",
- "piece": "img3-en.jpg",
+ "name": toAbsolutePath("img3-en.jpg"),
+ "piece": toAbsoluteUrl("img3-en.jpg"),
"target": "http://img3.example.com"
},
{
@@ -3089,6 +3125,17 @@ if ($sqlite) {
}, 1500);
+ var trackingRequests = [
+ null,
+ 'c_n=' + toAbsolutePath('img1-en.jpg', true) + '&c_p=' + toAbsoluteUrl('img1-en.jpg', true),
+ 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fimg2.example.com',
+ 'c_n=' + toAbsolutePath('img3-en.jpg', true) + '&c_p=' + toAbsoluteUrl('img3-en.jpg', true) + '&c_t=http%3A%2F%2Fimg3.example.com',
+ 'c_n=My%20content%204&c_p=My%20content%204&c_t=http%3A%2F%2Fimg4.example.com',
+ 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=' + originEncoded + '%2Fanylink5',
+ 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fimg6.example.com',
+ 'c_n=My%20Ad%207&c_p=Unknown&c_t=http%3A%2F%2Fimg7.example.com'
+ ];
+
stop();
setTimeout(function() {
removeContentTrackingFixture();
@@ -3100,13 +3147,13 @@ if ($sqlite) {
var requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
- assertTrackingRequest(requests[0], 'c_n=My%20Ad%207&c_p=Unknown&c_t=http%3A%2F%2Fimg7.example.com');
- assertTrackingRequest(requests[1], 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fimg6.example.com');
- assertTrackingRequest(requests[2], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=' + originEncoded + '%2Fanylink5');
- assertTrackingRequest(requests[3], 'c_n=My%20content%204&c_p=My%20content%204&c_t=http%3A%2F%2Fimg4.example.com');
- assertTrackingRequest(requests[4], 'c_n=img3-en.jpg&c_p=img3-en.jpg&c_t=http%3A%2F%2Fimg3.example.com');
- assertTrackingRequest(requests[5], 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fimg2.example.com');
- assertTrackingRequest(requests[6], 'c_n=img1-en.jpg&c_p=img1-en.jpg');
+ assertTrackingRequest(requests[0], trackingRequests[7]);
+ assertTrackingRequest(requests[1], trackingRequests[6]);
+ assertTrackingRequest(requests[2], trackingRequests[5]);
+ assertTrackingRequest(requests[3], trackingRequests[4]);
+ assertTrackingRequest(requests[4], trackingRequests[3]);
+ assertTrackingRequest(requests[5], trackingRequests[2]);
+ assertTrackingRequest(requests[6], trackingRequests[1]);
// trackContentImpressionsWithinNode()
@@ -3116,9 +3163,9 @@ if ($sqlite) {
requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
- assertTrackingRequest(requests[0], 'c_n=My%20content%204&c_p=My%20content%204&c_t=http%3A%2F%2Fimg4.example.com');
- assertTrackingRequest(requests[1], 'c_n=img3-en.jpg&c_p=img3-en.jpg&c_t=http%3A%2F%2Fimg3.example.com');
- assertTrackingRequest(requests[2], 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fimg2.example.com');
+ assertTrackingRequest(requests[0], trackingRequests[4]);
+ assertTrackingRequest(requests[1], trackingRequests[3]);
+ assertTrackingRequest(requests[2], trackingRequests[2]);
// trackContentImpression()
results = fetchTrackedRequests(token3);
@@ -3178,8 +3225,8 @@ if ($sqlite) {
requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
- assertTrackingRequest(requests[0], 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fimg6.example.com');
- assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=' + originEncoded + '%2Fanylink5');
+ assertTrackingRequest(requests[0], trackingRequests[6]);
+ assertTrackingRequest(requests[1], trackingRequests[5]);
// trackVisibleContentImpressions()
@@ -3189,9 +3236,9 @@ if ($sqlite) {
requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
- assertTrackingRequest(requests[0], 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fimg6.example.com');
- assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=' + originEncoded + '%2Fanylink5');
- assertTrackingRequest(requests[2], 'c_n=img1-en.jpg&c_p=img1-en.jpg');
+ assertTrackingRequest(requests[0], trackingRequests[6]);
+ assertTrackingRequest(requests[1], trackingRequests[5]);
+ assertTrackingRequest(requests[2], trackingRequests[1]);
// enableTrackOnlyVisibleContent(false, 500)
@@ -3201,12 +3248,12 @@ if ($sqlite) {
var requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
- assertTrackingRequest(requests[0], 'c_n=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_p=http%3A%2F%2Fwww.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fimg6.example.com');
- assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=' + originEncoded + '%2Fanylink5');
- assertTrackingRequest(requests[2], 'c_n=img1-en.jpg&c_p=img1-en.jpg');
- assertTrackingRequest(requests[3], 'c_n=My%20content%204&c_p=My%20content%204&c_t=http%3A%2F%2Fimg4.example.com');
- assertTrackingRequest(requests[4], 'c_n=img3-en.jpg&c_p=img3-en.jpg&c_t=http%3A%2F%2Fimg3.example.com');
- assertTrackingRequest(requests[5], 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fimg2.example.com');
+ assertTrackingRequest(requests[0], trackingRequests[6]);
+ assertTrackingRequest(requests[1], trackingRequests[5]);
+ assertTrackingRequest(requests[2], trackingRequests[1]);
+ assertTrackingRequest(requests[3], trackingRequests[4]);
+ assertTrackingRequest(requests[4], trackingRequests[3]);
+ assertTrackingRequest(requests[5], trackingRequests[2]);
// enableTrackOnlyVisibleContent(true, 0)