function FluidbookStats() {
+ this.hasMatomoTagManager = this.setupMatomoTagManager();
this.setupMatomo();
}
FluidbookStats.prototype = {
+ setupMatomoTagManager: function () {
+ if (SETTINGS.matomoTagManager !== '') {
+ var _mtm = window._mtm = window._mtm || [];
+ _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
+ var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
+ g.async = true;
+ g.src = '//' + SETTINGS.matomoTagManager;
+ s.parentNode.insertBefore(g, s);
+ return true;
+ }
+ return false;
+ },
+
setupMatomo: function () {
this.matomoServers = [];
- if (SETTINGS.statsMatomo) {
+ if (SETTINGS.statsMatomo && !this.hasMatomoTagManager) {
if (SETTINGS.statsMatomoServer === undefined || SETTINGS.statsMatomoServer === null) {
SETTINGS.statsMatomoServer = '3';
}
lastURL: '',
referer: '',
fullURL: false,
+ mtm: false,
});
}
- if (SETTINGS.matomoServer && SETTINGS.matomoSiteId) {
+ if (SETTINGS.matomoServer && SETTINGS.matomoSiteId && !this.hasMatomoTagManager) {
this.matomoServers.push({
server: SETTINGS.matomoServer,
siteId: SETTINGS.matomoSiteId,
lastURL: '',
referer: '',
- fullURL: true
+ fullURL: true,
+ mtm: false,
});
}
- if (this.matomoServers.length > 0) {
+ if (this.matomoServers.length > 0 && !this.hasMatomoTagManager) {
let u = 'https://' + this.matomoServers[0].server + '/';
window._paq = window._paq || [];
window._paq.push(["setDoNotTrack", true]);
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
}
+
+ if (this.hasMatomoTagManager) {
+ this.matomoServers.push({mtm: true, fullURL: true, lastURL: '', referer: ''});
+ }
+ },
+
+ matomoTrack(type, page, extra, url) {
+ if (url === undefined) {
+ url = window.location;
+ }
+ switch (type) {
+ case 0: // Change page
+ this.matomoViewPage(page);
+ break;
+ case 14: // Open chapters menu
+ this.matomoPush(['trackEvent', 'menu', 'click', 'chapters']);
+ break;
+ case 6: // Click a link in a page
+ this.matomoPush(['trackEvent', 'link', 'click', extra]);
+ this.matomoPush(['trackLink', extra]);
+ break;
+ case 1: // Search
+ this.matomoPush(['trackSiteSearch', extra]);
+ break;
+ case 3: // Print
+ this.matomoPush(['trackEvent', 'menu', 'click', 'print']);
+ break;
+ case 5: // Share
+ case 12: // Facebook
+ case 13: // Twitter
+ this.matomoPush(['trackEvent', 'share', 'send', extra]);
+ break;
+ case 7: // PDF
+ case 8: // Partial PDF
+ this.matomoPush(['trackEvent', 'menu', 'click', 'download']);
+ break;
+ case 4: // Bookmarks
+ this.matomoPush(['trackEvent', 'bookmark', 'page', 'page ' + page]);
+ break;
+ case 9: // Extras
+ this.matomoPush(['trackEvent', 'extra', 'click', extra]);
+ break;
+ case 2:// Zoom
+ this.matomoPush(['trackEvent', 'zoom', 'page', page]);
+ break;
+ case 15://
+ this.matomoPush(['trackEvent', 'cart', 'addproduct', extra]);
+ }
+ },
+
+ matomoViewPage: function (page) {
+ for (let i in this.matomoServers) {
+ let s = this.matomoServers[i];
+ let url = s.fullURL ? this.baseURL : 'http://fluidbook.' + s.siteId;
+ url += '/page/' + page;
+ s.referer = this.matomoServers[i].lastURL = s.lastURL;
+ s.lastURL = this.matomoServers[i].lastURL = url;
+ this.matomoPushToServer(['trackPageView', 'View page ' + page], s);
+ }
+ },
+
+ matomoPushToServer: function (data, server) {
+ if (this.matomoServers.length > 1) {
+ window._paq.push(['setTrackerUrl', 'https://' + server.server + '/matomo.php']);
+ window._paq.push(['setSiteId', server.siteId]);
+ if (server.referer !== '' && server.referer !== server.lastURL) {
+ _paq.push(['setReferrerUrl', server.referer]);
+ }
+ window._paq.push(['setCustomUrl', server.lastURL]);
+ } else if (data[0] === 'trackPageView') {
+ window._paq.push(['setCustomUrl', server.lastURL]);
+ }
+ window._paq.push(data);
+ },
+
+ matomoPush(data) {
+ for (let i in this.matomoServers) {
+ let dataCopy = data.slice(0);
+ this.matomoPushToServer(dataCopy, this.matomoServers[i]);
+ }
},
setup: function (fluidbook) {
}
},
- matomoTrack(type, page, extra, url) {
- if (url === undefined) {
- url = window.location;
- }
- switch (type) {
- case 0: // Change page
- this.matomoViewPage(page);
- break;
- case 14: // Open chapters menu
- this.matomoPush(['trackEvent', 'menu', 'click', 'chapters']);
- break;
- case 6: // Click a link in a page
- this.matomoPush(['trackEvent', 'link', 'click', extra]);
- this.matomoPush(['trackLink', extra]);
- break;
- case 1: // Search
- this.matomoPush(['trackSiteSearch', extra]);
- break;
- case 3: // Print
- this.matomoPush(['trackEvent', 'menu', 'click', 'print']);
- break;
- case 5: // Share
- case 12: // Facebook
- case 13: // Twitter
- this.matomoPush(['trackEvent', 'share', 'send', extra]);
- break;
- case 7: // PDF
- case 8: // Partial PDF
- this.matomoPush(['trackEvent', 'menu', 'click', 'download']);
- break;
- case 4: // Bookmarks
- this.matomoPush(['trackEvent', 'bookmark', 'page', 'page ' + page]);
- break;
- case 9: // Extras
- this.matomoPush(['trackEvent', 'extra', 'click', extra]);
- break;
- case 2:// Zoom
- this.matomoPush(['trackEvent', 'zoom', 'page', page]);
- break;
- case 15://
- this.matomoPush(['trackEvent', 'cart', 'addproduct', extra]);
- }
- },
-
- matomoViewPage: function (page) {
- for (var i in this.matomoServers) {
- let s = this.matomoServers[i];
- let url = s.fullURL ? this.baseURL : 'http://fluidbook.' + s.siteId;
- url += '/page/' + page;
- s.referer = this.matomoServers[i].lastURL = s.lastURL;
- s.lastURL = this.matomoServers[i].lastURL = url;
- this.matomoPushToServer(['trackPageView', 'View page ' + page], s);
- }
- },
-
- matomoPushToServer: function (data, server) {
- if (this.matomoServers.length > 1) {
- window._paq.push(['setTrackerUrl', 'https://' + server.server + '/matomo.php']);
- window._paq.push(['setSiteId', server.siteId]);
- if (server.referer !== '' && server.referer !== server.lastURL) {
- _paq.push(['setReferrerUrl', server.referer]);
- }
- window._paq.push(['setCustomUrl', server.lastURL]);
- } else if (data[0] === 'trackPageView') {
- window._paq.push(['setCustomUrl', server.lastURL]);
- }
- window._paq.push(data);
- },
-
- matomoPush(data) {
- for (let i in this.matomoServers) {
- let dataCopy = data.slice(0);
- this.matomoPushToServer(dataCopy, this.matomoServers[i]);
- }
- },
trackGoogleAnalytics: function (type, page, extra, url) {
this.checkGoogleAnalytics();