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:
-rw-r--r--js/piwik.js184
-rw-r--r--misc/internal-docs/content-tracking.md47
-rw-r--r--tests/javascript/content-fixtures/trackingContent.html21
-rw-r--r--tests/javascript/index.php142
4 files changed, 239 insertions, 155 deletions
diff --git a/js/piwik.js b/js/piwik.js
index b01a61dc6c..d230e07914 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -447,12 +447,12 @@ if (typeof JSON2 !== 'object') {
getQuery, getContent, getContentImpressionsRequestsFromNodes, buildContentInteractionTrackingRedirectUrl,
buildContentInteractionRequestNode, buildContentInteractionRequest, buildContentImpressionRequest,
appendContentInteractionToRequestIfPossible, setupInteractionsTracking, trackContentImpressionClickInteraction,
- internalIsNodeVisible, clearTrackedContentImpressions, getTrackerUrl, trackContentImpressions,
+ internalIsNodeVisible, clearTrackedContentImpressions, getTrackerUrl, trackAllContentImpressions,
getTrackedContentImpressions, getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet,
contentInteractionTrackingSetupDone, contains, match, pathname, piece, trackContentInteractionNode,
trackContentInteractionNode, trackContentImpressionsWithinNode, trackContentImpression,
enableTrackOnlyVisibleContent, trackContentInteraction, clearEnableTrackOnlyVisibleContent,
- trackVisibleContentImpressions
+ trackVisibleContentImpressions, isTrackOnlyVisibleContentEnabled
*/
/*global _paq:true */
/*members push */
@@ -1812,7 +1812,13 @@ if (typeof Piwik !== 'object') {
},
getLocation: function ()
{
- return this.location || windowAlias.location;
+ var locationAlias = this.location || windowAlias.location;
+
+ if (!locationAlias.origin) {
+ locationAlias.origin = locationAlias.protocol + "//" + locationAlias.hostname + (locationAlias.port ? ':' + locationAlias.port: '');
+ }
+
+ return locationAlias;
},
toAbsoluteUrl: function (url)
{
@@ -2110,7 +2116,7 @@ if (typeof Piwik !== 'object') {
// Keeps track of previously tracked content impressions
trackedContentImpressions = [],
- enableTrackOnlyVisibleContent = false,
+ isTrackOnlyVisibleContentEnabled = false,
// Guard against installing the link tracker more than once per Tracker instance
linkTrackingInstalled = false,
@@ -3500,6 +3506,72 @@ if (typeof Piwik !== 'object') {
}
}
}
+ function enableTrackOnlyVisibleContent (checkOnSroll, timeIntervalInMs, tracker) {
+
+ if (isTrackOnlyVisibleContentEnabled) {
+ // already enabled, do not register intervals again
+ return true;
+ }
+
+ isTrackOnlyVisibleContentEnabled = true;
+
+ var didScroll = false;
+ var events, index;
+
+ function setDidScroll() { didScroll = true; }
+
+ trackCallbackOnLoad(function () {
+
+ function checkContent(intervalInMs) {
+ setTimeout(function () {
+ if (!isTrackOnlyVisibleContentEnabled) {
+ return; // the tests stopped tracking only visible content
+ }
+ didScroll = false;
+ tracker.trackVisibleContentImpressions();
+ checkContent(intervalInMs);
+ }, intervalInMs);
+ }
+
+ function checkContentIfDidScroll(intervalInMs) {
+
+ setTimeout(function () {
+ if (!isTrackOnlyVisibleContentEnabled) {
+ return; // the tests stopped tracking only visible content
+ }
+
+ if (didScroll) {
+ didScroll = false;
+ tracker.trackVisibleContentImpressions();
+ }
+
+ checkContentIfDidScroll(intervalInMs);
+ }, intervalInMs);
+ }
+
+ if (checkOnSroll) {
+
+ // scroll event is executed after each pixel, so we make sure not to
+ // execute event too often. otherwise FPS goes down a lot!
+ events = ['scroll', 'resize'];
+ for (index = 0; index < events.length; index++) {
+ if (documentAlias.addEventListener) {
+ documentAlias.addEventListener(events[index], setDidScroll);
+ } else {
+ windowAlias.attachEvent('on' + events[index], setDidScroll);
+ }
+ }
+
+ checkContentIfDidScroll(100);
+ }
+
+ if (timeIntervalInMs && timeIntervalInMs > 0) {
+ timeIntervalInMs = parseInt(timeIntervalInMs, 10);
+ checkContent(timeIntervalInMs);
+ }
+
+ });
+ }
/*
* Browser features (plugins, resolution, cookies)
@@ -3636,6 +3708,9 @@ if (typeof Piwik !== 'object') {
setupInteractionsTracking: setupInteractionsTracking,
trackContentImpressionClickInteraction: trackContentImpressionClickInteraction,
internalIsNodeVisible: isVisible,
+ enableTrackOnlyVisibleContent: function (checkOnScroll, timeIntervalInMs) {
+ return enableTrackOnlyVisibleContent(checkOnScroll, timeIntervalInMs, this);
+ },
clearTrackedContentImpressions: function () {
trackedContentImpressions = [];
},
@@ -3646,9 +3721,8 @@ if (typeof Piwik !== 'object') {
return configTrackerUrl;
},
clearEnableTrackOnlyVisibleContent: function () {
- enableTrackOnlyVisibleContent = false;
+ isTrackOnlyVisibleContentEnabled = false;
},
-
/*</DEBUG>*/
/**
@@ -4360,18 +4434,19 @@ if (typeof Piwik !== 'object') {
}
},
- enableTrackOnlyVisibleContent: function (checkOnSroll, timeIntervalInMs) {
- var self = this;
- var didScroll = false;
-
- function setDidScroll() { didScroll = true; }
+ trackAllContentImpressions: function () {
+ trackCallback(function () {
+ trackCallbackOnReady(function () {
+ // we have to wait till DOM ready
+ var contentNodes = content.findContentNodes();
- if (enableTrackOnlyVisibleContent) {
- // already enabled, do not register intervals again
- return true;
- }
+ var requests = getContentImpressionsRequestsFromNodes(contentNodes);
+ sendBulkRequest(requests, configTrackerPause);
+ });
+ });
+ },
- enableTrackOnlyVisibleContent = true;
+ trackVisibleContentImpressions: function (checkOnSroll, timeIntervalInMs) {
if (!isDefined(checkOnSroll)) {
checkOnSroll = true;
@@ -4381,79 +4456,19 @@ if (typeof Piwik !== 'object') {
timeIntervalInMs = 750;
}
- trackCallbackOnLoad(function () {
- var events, index;
-
- function checkContent(intervalInMs) {
- setTimeout(function () {
- didScroll = false;
- self.trackContentImpressions();
- checkContent(intervalInMs);
- }, intervalInMs);
- }
-
- function checkContentIfDidScroll(intervalInMs) {
- setTimeout(function () {
- if (didScroll) {
- didScroll = false;
- self.trackContentImpressions();
- }
-
- checkContentIfDidScroll(intervalInMs);
- }, intervalInMs);
- }
-
- if (checkOnSroll) {
-
- // scroll event is executed after each pixel, so we make sure not to
- // execute event too often. otherwise FPS goes down a lot!
- events = ['scroll', 'resize'];
- for (index = 0; index < events.length; index++) {
- if (windowAlias.addEventListener) {
- windowAlias.addEventListener(events[index], setDidScroll);
- } else {
- windowAlias.attachEvent('on' + events[index], setDidScroll);
- }
- }
-
- checkContentIfDidScroll(100);
- }
-
- if (timeIntervalInMs && timeIntervalInMs > 0) {
- timeIntervalInMs = parseInt(timeIntervalInMs, 10);
- checkContent(timeIntervalInMs);
- }
+ enableTrackOnlyVisibleContent(checkOnSroll, timeIntervalInMs, this);
- });
- },
-
- trackContentImpressions: function () {
trackCallback(function () {
- if (enableTrackOnlyVisibleContent) {
- trackCallbackOnLoad(function () {
- // we have to wait till CSS parsed and applied
- var contentNodes = content.findContentNodes();
-
- var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes);
- sendBulkRequest(requests, configTrackerPause);
- });
- } else {
- trackCallbackOnReady(function () {
- // we have to wait till DOM ready
- var contentNodes = content.findContentNodes();
+ trackCallbackOnLoad(function () {
+ // we have to wait till CSS parsed and applied
+ var contentNodes = content.findContentNodes();
- var requests = getContentImpressionsRequestsFromNodes(contentNodes);
- sendBulkRequest(requests, configTrackerPause);
- });
- }
+ var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes);
+ sendBulkRequest(requests, configTrackerPause);
+ });
});
},
- trackVisibleContentImpressions: function (checkOnSroll, timeIntervalInMs) {
- this.enableTrackOnlyVisibleContent(checkOnSroll, timeIntervalInMs);
- this.trackContentImpressions();
- },
-
// it must be a node that is set to .piwikTrackContent or [data-track-content] or one of its parents nodes
trackContentImpression: function (contentName, contentPiece, contentTarget) {
if (!contentName) {
@@ -4472,7 +4487,7 @@ if (typeof Piwik !== 'object') {
// we might remove this method again
trackContentImpressionsWithinNode: function (domNode) {
trackCallback(function () {
- if (enableTrackOnlyVisibleContent) {
+ if (isTrackOnlyVisibleContentEnabled) {
trackCallbackOnLoad(function () {
// we have to wait till CSS parsed and applied
var contentNodes = content.findContentNodesWithinNode(domNode);
@@ -4541,7 +4556,6 @@ if (typeof Piwik !== 'object') {
});
},
-
/**
* Used to record that the current page view is an item (product) page view, or a Ecommerce Category page view.
* This must be called before trackPageView() on the product/category page.
diff --git a/misc/internal-docs/content-tracking.md b/misc/internal-docs/content-tracking.md
index 19c950af5a..1df16dc17b 100644
--- a/misc/internal-docs/content-tracking.md
+++ b/misc/internal-docs/content-tracking.md
@@ -302,31 +302,15 @@ A typical example for a content block that displays a text ad.
There are several ways to track a content impression and/or interaction manually, semi-automatically and automatically. Please be aware that content impressions will be tracked using bulk tracking which will always send a `POST` request, even if `GET` is configured which is the default.
-#### `trackContentImpressions()`
+#### `trackAllContentImpressions()`
You can use this method to scan the entire DOM for content blocks.
-For each content block we will track a content impression immediately unless you enable `enableTrackOnlyVisibleContent` see below.
+For each content block we will track a content impression immediately unless you have called `trackVisibleContentImpressions()` before see below.
Note: We will not send an impression of the same content block twice if you call this method multiple times unless `trackPageView()` is called meanwhile. This is useful for single page applications. The "same" content blocks means if a content block has the identical name, piece and target as an already tracked one.
Note: At this stage we do not exeute this method automatically along with a trackPageView(), we can do this later once we know it works
-#### `trackContentImpressionsWithinNode(domNode, contentTarget)`
-
-You can use this method if you, for instance, dynamically add an element using JavaScript to your DOM after the we have tracked the initial impressions. Calling this method will make sure an impression will be tracked for all content blocks contained within this node.
-
-Example
-```
-var div = $('<div>...<div data-track-content>...</div>...<div data-track-content>...</div></div>');
-$('#id').append(div);
-
-_paq.push(['trackContentImpressionsWithinNode', div[0]]);
-```
-
-We would detect two new content blocks in this example.
-
-Please note: In case you have enabled to only track visible content blocks we will respect this. In case it contains a content block that was already tracked we will not track it again.
-
-#### `enableTrackOnlyVisibleContent(checkOnSroll, timeIntervalInMs)`
+#### `trackVisibleContentImpressions(checkOnSroll, timeIntervalInMs)`
If you enable to track only visible content we will only track an impression if a content block is actually visible. With visible we mean the content block has been in the view port, it is actually in the DOM and is not hidden via CSS (opacity, visibility, display, ...).
* Optionally you can tell us to rescan the DOM automatically after each scroll event by passing `checkOnSroll=true`. We will then check whether the previously hidden content blocks are visible now and if so track the impression.
@@ -338,14 +322,33 @@ If you enable to track only visible content we will only track an impression if
* Rescanning the entire DOM and detecting the visible state of content blocks can take a while depending on the browser and amount of content
* We do not really rescan every X milliseconds. We will schedule the next rescan after a previous scan has finished. So if it takes 20ms to scan the DOM and you tell us to rescan every 50ms it can actually take 70ms.
* In case your frames per second goes down you might want to increase this value
-* If you do not want us to perform any checks you can either call `trackContentImpressions()` manually at any time to rescan the entire DOM or `trackContentImpressionsWithinNode()` to check only a specific part of the DOM for visible content blocks.
+* If you do want to only track visible content but not want us to perform any checks automatically you can either call `trackVisibleContentImpressions()` manually at any time to rescan the entire DOM or `trackContentImpressionsWithinNode()` to check only a specific part of the DOM for visible content blocks.
+ * Call `trackVisibleContentImpressions(false, 0)` to initially track only visible content impressions
+ * Call `trackVisibleContentImpressions()` at any time again to rescan the entire DOM for newly visible content blocks or
+ * Call `trackContentImpressionsWithinNode(node)` at any time to rescan only a part of the DOM for newly visible content blocks
-It is recommended to call this method once before any call to `trackContentImpressions` or `trackContentImpressionsWithinNode()`. If you call this method more than once it does not have any effect.
+Note: You can not change the `checkOnScroll` or `timeIntervalInMs` after this method was called the first time.
-#### `trackVisibleContentImpressions(checkOnSroll, timeIntervalInMs)`
+#### `(checkOnSroll, timeIntervalInMs)`
Is a shorthand for calling `enableTrackOnlyVisibleContent()` and `trackContentImpressions()`.
+#### `trackContentImpressionsWithinNode(domNode, contentTarget)`
+
+You can use this method if you, for instance, dynamically add an element using JavaScript to your DOM after the we have tracked the initial impressions. Calling this method will make sure an impression will be tracked for all content blocks contained within this node.
+
+Example
+```
+var div = $('<div>...<div data-track-content>...</div>...<div data-track-content>...</div></div>');
+$('#id').append(div);
+
+_paq.push(['trackContentImpressionsWithinNode', div[0]]);
+```
+
+We would detect two new content blocks in this example.
+
+Please note: In case you have enabled to only track visible content blocks we will respect this. In case it contains a content block that was already tracked we will not track it again.
+
#### trackContentInteractionNode(domNode, contentInteraction)
By default we track interactions depending on a click and sometimes we cannot track interactions automatically add all. See "How do we track an interaction automatically?". In case you want to track an interaction manually for instance on a double click or on a form submit you can do this as following:
diff --git a/tests/javascript/content-fixtures/trackingContent.html b/tests/javascript/content-fixtures/trackingContent.html
new file mode 100644
index 0000000000..e78a1f043f
--- /dev/null
+++ b/tests/javascript/content-fixtures/trackingContent.html
@@ -0,0 +1,21 @@
+<div>
+ <img src="img1-en.jpg" data-track-content/>
+ <img src="img1-en.jpg" class="piwikTrackContent"/> <!-- same as before should be ignored -->
+ <div id="block1" style="display: none;">
+ <a href="http://img2.example.com" data-track-content><img src="img2-en.jpg" data-content-piece="img.jpg"/></a>
+ <a href="http://img3.example.com" data-track-content><img src="img3-en.jpg" data-content-piece/></a>
+ <a href="http://img4.example.com" data-track-content><p data-content-piece="My content 4">Lorem ipsum</p></a>
+ </div>
+ <div id="block2">
+ <div id="ex5" data-track-content data-content-name="My Ad 5">
+ <img src="http://img5.example.com/path/xyz.jpg" data-content-piece />
+ <a href="/anylink5" data-content-target>Lorem ipsum</a>
+ </div>
+ <a href="http://img6.example.com" data-track-content>
+ <img src="http://www.example.com/path/xyz.jpg" data-content-piece />
+ </a>
+ <a href="http://img7.example.com" data-track-content data-content-name="My Ad 7" style="visibility:hidden;">
+ Lorem ipsum
+ </a>
+ </div>
+</div> \ No newline at end of file
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index 6d9a5e55ee..698ce3fec5 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -85,6 +85,14 @@ function _s(selector) { // select node within content test scope
}
}
+ function getOrigin()
+ {
+ if (window.location.origin) {
+ return window.location.origin;
+ }
+ return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
+ }
+
function loadJash() {
var jashDiv = _e('jashDiv');
@@ -99,7 +107,7 @@ function loadJash() {
function triggerEvent(element, type) {
if ( document.createEvent ) {
- event = document.createEvent( "MouseEvents" );
+ var event = document.createEvent( "MouseEvents" );
event.initMouseEvent(type, true, true, element.ownerDocument.defaultView,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
element.dispatchEvent( event );
@@ -939,7 +947,7 @@ function PiwikTest() {
}
var locationAlias = $.extend({}, window.location);
- var origin = locationAlias.origin;
+ var origin = getOrigin();
var host = locationAlias.host;
ok("test trim(text)");
@@ -1270,7 +1278,7 @@ function PiwikTest() {
setupContentTrackingFixture('manyExamples');
- var origin = location.origin;
+ var origin = getOrigin();
var host = location.host;
assertFoundContent(undefined, undefined, undefined, undefined, 'No node set');
@@ -1352,7 +1360,7 @@ function PiwikTest() {
var impression = {name: 'name', piece: '5', target: 'target'};
- var origin = location.origin;
+ var origin = getOrigin();
var originEncoded = window.encodeURIComponent(origin);
function assertTrackingRequest(actual, expectedStartsWith, message)
@@ -1652,7 +1660,7 @@ function PiwikTest() {
});
test("API methods", function() {
- expect(64);
+ expect(63);
equal( typeof Piwik.addPlugin, 'function', 'addPlugin' );
equal( typeof Piwik.getTracker, 'function', 'getTracker' );
@@ -1715,8 +1723,7 @@ function PiwikTest() {
equal( typeof tracker.trackLink, 'function', 'trackLink' );
equal( typeof tracker.trackPageView, 'function', 'trackPageView' );
// content
- equal( typeof tracker.enableTrackOnlyVisibleContent, 'function', 'enableTrackOnlyVisibleContent' );
- equal( typeof tracker.trackContentImpressions, 'function', 'trackContentImpressions' );
+ equal( typeof tracker.trackAllContentImpressions, 'function', 'trackAllContentImpressions' );
equal( typeof tracker.trackVisibleContentImpressions, 'function', 'trackVisibleContentImpressions' );
equal( typeof tracker.trackContentImpression, 'function', 'trackContentImpression' );
equal( typeof tracker.trackContentImpressionsWithinNode, 'function', 'trackContentImpressionsWithinNode' );
@@ -2650,7 +2657,7 @@ if ($sqlite) {
});
test("trackingContent", function() {
- expect(65);
+ expect(77);
function assertTrackingRequest(actual, expectedStartsWith, message)
{
@@ -2666,14 +2673,20 @@ if ($sqlite) {
strictEqual(actual.indexOf('&idsite=1&rec=1'), expectedStartsWith.length);
}
+ function resetTracker(track, token)
+ {
+ tracker.clearTrackedContentImpressions();
+ tracker.clearEnableTrackOnlyVisibleContent();
+ tracker.setCustomData('token', token);
+ scrollToTop();
+ }
+
var token = getContentToken();
var tracker = Piwik.getTracker();
tracker.setTrackerUrl("piwik.php");
tracker.setSiteId(1);
- tracker.setCustomData({ "token" : token });
- tracker.clearEnableTrackOnlyVisibleContent();
- tracker.clearTrackedContentImpressions();
+ resetTracker(tracker, token);
var visitorIdStart = tracker.getVisitorId();
// need to wait at least 1 second so that the cookie would be different, if it wasnt persisted
@@ -2681,7 +2694,7 @@ if ($sqlite) {
var actual, expected, trackerUrl;
- tracker.trackContentImpressions();
+ tracker.trackAllContentImpressions();
strictEqual(tracker.getTrackedContentImpressions().length, 0, 'getTrackedContentImpressions, there is no content block to track');
tracker.trackContentImpressionsWithinNode(_e('other'));
strictEqual(tracker.getTrackedContentImpressions().length, 0, 'getTrackedContentImpressionsWithinNode, there is no content block to track');
@@ -2690,14 +2703,13 @@ if ($sqlite) {
setupContentTrackingFixture('trackingContent', document.body);
- tracker.trackContentImpressions();
+ tracker.trackAllContentImpressions();
strictEqual(tracker.getTrackedContentImpressions().length, 7, 'should mark 7 content blocks as tracked');
wait(500);
var token2 = '2' + token;
- tracker.clearTrackedContentImpressions();
- tracker.setCustomData('token', token2);
+ resetTracker(tracker, token2);
tracker.trackContentImpressionsWithinNode(_s('#block1'));
strictEqual(tracker.getTrackedContentImpressions().length, 3, 'should mark 3 content blocks as tracked');
@@ -2708,8 +2720,7 @@ if ($sqlite) {
wait(500);
var token3 = '3' + token;
- tracker.clearTrackedContentImpressions();
- tracker.setCustomData('token', token3);
+ resetTracker(tracker, token3);
tracker.trackContentImpression(); // should not track anything as name is required
tracker.trackContentImpression('MyName'); // piece should default to Unknown
wait(500);
@@ -2719,7 +2730,7 @@ if ($sqlite) {
wait(500);
var token4 = '4' + token;
- tracker.setCustomData('token', token4);
+ resetTracker(tracker, token4);
tracker.trackContentInteraction(); // should not track anything as interaction and name is required
tracker.trackContentInteraction('Clicki'); // should not track anything as interaction and name is required
tracker.trackContentInteraction('Clicke', 'IntName'); // should use default for piece and ignore target as it is not set
@@ -2729,25 +2740,20 @@ if ($sqlite) {
wait(500);
var token5 = '5' + token;
- tracker.clearTrackedContentImpressions();
- tracker.setCustomData('token', token5);
+ resetTracker(tracker, token5);
tracker.trackContentInteractionNode(_s('#ex5'), 'Clicki?iii');
wait(500);
var token6 = '6' + token;
- tracker.clearTrackedContentImpressions();
+ resetTracker(tracker, token6);
tracker.enableTrackOnlyVisibleContent(false, 0);
- tracker.setCustomData('token', token6);
- scrollToTop();
- tracker.trackContentImpressions();
- strictEqual(tracker.getTrackedContentImpressions().length, 3, 'should only track visible ones this time');
+ tracker.trackAllContentImpressions();
+ strictEqual(tracker.getTrackedContentImpressions().length, 7, 'should still track all impressions even if visible enabled');
var token7 = '7' + token;
- tracker.clearTrackedContentImpressions();
- tracker.enableTrackOnlyVisibleContent();
- tracker.setCustomData('token', token7);
- scrollToTop();
+ resetTracker(tracker, token7);
+ tracker.enableTrackOnlyVisibleContent(false, 0);
tracker.trackContentImpressionsWithinNode();
strictEqual(tracker.getTrackedContentImpressions().length, 0, 'should not track anything, no node provided');
tracker.trackContentImpressionsWithinNode(_s('#block1'));
@@ -2758,22 +2764,50 @@ if ($sqlite) {
wait(500);
var token8 = '8' + token;
- tracker.clearTrackedContentImpressions();
- tracker.clearEnableTrackOnlyVisibleContent();
- tracker.setCustomData('token', token8);
- scrollToTop();
- tracker.trackVisibleContentImpressions(false, 0);
+ resetTracker(tracker, token8);
+ tracker.trackVisibleContentImpressions(false, 0, tracker);
strictEqual(tracker.getTrackedContentImpressions().length, 3, 'should only track all visible impressions');
- removeContentTrackingFixture();
+ wait(500);
+
+ // test detection of content via interval
+ var token9 = '9' + token;
+ var token10 = '10' + token;
+ resetTracker(tracker, token9);
+ tracker.trackVisibleContentImpressions(false, 500);
+ strictEqual(tracker.getTrackedContentImpressions().length, 3, 'should only track all visible impressions, timeInterval');
+ _s('#block1').style.display = 'block';
+ scrollToTop();
+
+ setTimeout(function () {
+ strictEqual(tracker.getTrackedContentImpressions().length, 6, 'should now have tracked 6 impressions via time interval');
+ tracker.clearEnableTrackOnlyVisibleContent(); // stop visible content time interval check
+
+ // test detection of content via scroll
+ setTimeout(function () {
+ _s('#block1').style.display = 'none';
+ resetTracker(tracker, token10);
+ tracker.trackVisibleContentImpressions(true, 0);
+ strictEqual(tracker.getTrackedContentImpressions().length, 3, 'should trak 3 initial visible impressions, scroll');
+ _s('#block1').style.display = 'block';
+ window.scrollTo(0, 200); // should trigger scroll event
+ setTimeout(function () {
+ strictEqual(tracker.getTrackedContentImpressions().length, 6, 'should detect 3 more afer scroll');
+ tracker.clearEnableTrackOnlyVisibleContent(); // stop visible content scroll interval check
+ }, 500);
+
+ }, 250); // wait for time interval to stop.
+
+ }, 1500);
stop();
setTimeout(function() {
+ removeContentTrackingFixture();
- // trackContentImpressions()
+ // trackAllContentImpressions()
var results = fetchTrackedRequests(token);
- equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "7", "count trackContentImpressions requests. all content blocks should be tracked" );
+ equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "7", "count trackAllContentImpressions requests. all content blocks should be tracked" );
var requests = results.match(/<span\>(.*?)\<\/span\>/g);
requests.shift();
@@ -2842,16 +2876,9 @@ if ($sqlite) {
assertTrackingRequest(requests[0], 'c_i=Clicki%3Fiii&c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fapache.piwik%2Fanylink5');
- // enableTrackOnlyVisibleContent() && trackContentImpressions()
+ // enableTrackOnlyVisibleContent() && trackAllContentImpressions()
results = fetchTrackedRequests(token6);
- equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "3", "count enabledVisibleContentImpressions requests." );
-
- requests = results.match(/<span\>(.*?)\<\/span\>/g);
- requests.shift();
-
- assertTrackingRequest(requests[0], 'c_n=img1-en.jpg&c_p=img1-en.jpg');
- assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fapache.piwik%2Fanylink5');
- assertTrackingRequest(requests[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%2Fimg6.example.com');
+ equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "7", "count enabledVisibleContentImpressions requests." );
// enableTrackOnlyVisibleContent() && trackContentImpressionsWithinNode()
@@ -2876,10 +2903,29 @@ if ($sqlite) {
assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fapache.piwik%2Fanylink5');
assertTrackingRequest(requests[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%2Fimg6.example.com');
+
+ // enableTrackOnlyVisibleContent(false, 500)
+ results = fetchTrackedRequests(token9);
+ equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "6", "count automatically tracked requests via time interval. " );
+
+ var requests = results.match(/<span\>(.*?)\<\/span\>/g);
+ requests.shift();
+
+ assertTrackingRequest(requests[0], 'c_n=img1-en.jpg&c_p=img1-en.jpg');
+ assertTrackingRequest(requests[1], 'c_n=My%20Ad%205&c_p=http%3A%2F%2Fimg5.example.com%2Fpath%2Fxyz.jpg&c_t=http%3A%2F%2Fapache.piwik%2Fanylink5');
+ assertTrackingRequest(requests[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%2Fimg6.example.com');
+ assertTrackingRequest(requests[3], 'c_n=img.jpg&c_p=img.jpg&c_t=http%3A%2F%2Fimg2.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=My%20content%204&c_p=My%20content%204&c_t=http%3A%2F%2Fimg4.example.com');
+
+
+ // enableTrackOnlyVisibleContent(true, 0)
+ results = fetchTrackedRequests(token10);
+ equal( (/<span\>([0-9]+)\<\/span\>/.exec(results))[1], "6", "count automatically tracked requests, via scroll. " );
+
start();
- }, 5000);
+ }, 6000);
-// enableTrackOnlyVisibleContent (checkOnSroll, timeIntervalInMs)
});
<?php