@aller/blink-labrador
Advanced tools
Comparing version 0.6.4 to 0.6.8
@@ -1,14 +0,2 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.hasCMP = hasCMP; | ||
exports.getVendorConsents = getVendorConsents; | ||
exports.hasInformationStorageConsent = hasInformationStorageConsent; | ||
exports.hasPersonalisationConsent = hasPersonalisationConsent; | ||
exports.hasAdTrackingConsent = hasAdTrackingConsent; | ||
exports.hasContentTrackingConsent = hasContentTrackingConsent; | ||
exports.hasMeasurementConsent = hasMeasurementConsent; | ||
exports.hasEveryConsent = hasEveryConsent; | ||
"use strict"; | ||
/** | ||
@@ -24,32 +12,31 @@ * A typical response from OIL | ||
**/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function hasCMP() { | ||
return typeof window.__cmp === 'function'; | ||
return typeof window.__cmp === 'function'; | ||
} | ||
exports.hasCMP = hasCMP; | ||
function getVendorConsents(cb) { | ||
// Users are opted in by default (legitimate interest?) | ||
var defaultPurposes = { 1: true, 2: true, 3: true, 4: true, 5: true }; | ||
if (!hasCMP()) { | ||
cb({ | ||
purposeConsents: defaultPurposes | ||
// Users are opted in by default (legitimate interest?) | ||
var defaultPurposes = { 1: true, 2: true, 3: true, 4: true, 5: true }; | ||
if (!hasCMP()) { | ||
cb({ | ||
purposeConsents: defaultPurposes, | ||
}); | ||
return; | ||
} | ||
window.__cmp('getVendorConsents', null, function (result) { | ||
if (result && result.purposeConsents) { | ||
cb(result); | ||
} | ||
else { | ||
cb(defaultPurposes); | ||
} | ||
}); | ||
return; | ||
} | ||
window.__cmp('getVendorConsents', null, function (result) { | ||
if (result && result.purposeConsents) { | ||
cb(result); | ||
} else { | ||
cb(defaultPurposes); | ||
} | ||
}); | ||
} | ||
exports.getVendorConsents = getVendorConsents; | ||
function hasConsent(type, cb) { | ||
getVendorConsents(function (res) { | ||
cb(res.purposeConsents[type] || false); | ||
}); | ||
getVendorConsents(function (res) { | ||
cb(res.purposeConsents[type] || false); | ||
}); | ||
} | ||
var CMP_INFORMATION_STORAGE = 1; | ||
@@ -60,28 +47,33 @@ var CMP_PERSONALISATION = 2; | ||
var CMP_MEASUREMENT = 5; | ||
function hasInformationStorageConsent(cb) { | ||
hasConsent(CMP_INFORMATION_STORAGE, cb); | ||
hasConsent(CMP_INFORMATION_STORAGE, cb); | ||
} | ||
exports.hasInformationStorageConsent = hasInformationStorageConsent; | ||
function hasPersonalisationConsent(cb) { | ||
hasConsent(CMP_PERSONALISATION, cb); | ||
hasConsent(CMP_PERSONALISATION, cb); | ||
} | ||
exports.hasPersonalisationConsent = hasPersonalisationConsent; | ||
function hasAdTrackingConsent(cb) { | ||
hasConsent(CMP_AD_TRACKING, cb); | ||
hasConsent(CMP_AD_TRACKING, cb); | ||
} | ||
exports.hasAdTrackingConsent = hasAdTrackingConsent; | ||
function hasContentTrackingConsent(cb) { | ||
hasConsent(CMP_CONTENT_TRACKING, cb); | ||
hasConsent(CMP_CONTENT_TRACKING, cb); | ||
} | ||
exports.hasContentTrackingConsent = hasContentTrackingConsent; | ||
function hasMeasurementConsent(cb) { | ||
hasConsent(CMP_MEASUREMENT, cb); | ||
hasConsent(CMP_MEASUREMENT, cb); | ||
} | ||
exports.hasMeasurementConsent = hasMeasurementConsent; | ||
function hasEveryConsent(cb) { | ||
getVendorConsents(function (res) { | ||
var cons = res.purposeConsents; | ||
cb(cons[CMP_INFORMATION_STORAGE] && cons[CMP_PERSONALISATION] && cons[CMP_AD_TRACKING] && cons[CMP_CONTENT_TRACKING] && cons[CMP_MEASUREMENT]); | ||
}); | ||
} | ||
getVendorConsents(function (res) { | ||
var cons = res.purposeConsents; | ||
cb(cons[CMP_INFORMATION_STORAGE] && | ||
cons[CMP_PERSONALISATION] && | ||
cons[CMP_AD_TRACKING] && | ||
cons[CMP_CONTENT_TRACKING] && | ||
cons[CMP_MEASUREMENT]); | ||
}); | ||
} | ||
exports.hasEveryConsent = hasEveryConsent; | ||
//# sourceMappingURL=cmp.js.map |
519
lib/main.js
@@ -1,175 +0,78 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _allerInView = require('@soldotno/aller-in-view'); | ||
var _allerInView2 = _interopRequireDefault(_allerInView); | ||
var _blink = require('@aller/blink'); | ||
var _blink2 = _interopRequireDefault(_blink); | ||
var _throttle = require('lodash/throttle'); | ||
var _throttle2 = _interopRequireDefault(_throttle); | ||
var _beforeunload = require('./triggers/beforeunload'); | ||
var _beforeunload2 = _interopRequireDefault(_beforeunload); | ||
var _clickOnOutgoingLink = require('./triggers/click-on-outgoing-link'); | ||
var _clickOnOutgoingLink2 = _interopRequireDefault(_clickOnOutgoingLink); | ||
var _keydown = require('./triggers/keydown'); | ||
var _keydown2 = _interopRequireDefault(_keydown); | ||
var _mousemove = require('./triggers/mousemove'); | ||
var _mousemove2 = _interopRequireDefault(_mousemove); | ||
var _mousedown = require('./triggers/mousedown'); | ||
var _mousedown2 = _interopRequireDefault(_mousedown); | ||
var _visibilitychange = require('./triggers/visibilitychange'); | ||
var _visibilitychange2 = _interopRequireDefault(_visibilitychange); | ||
var _pageHide = require('./triggers/page-hide'); | ||
var _pageHide2 = _interopRequireDefault(_pageHide); | ||
var _unload = require('./triggers/unload'); | ||
var _unload2 = _interopRequireDefault(_unload); | ||
var _scroll = require('./triggers/scroll'); | ||
var _scroll2 = _interopRequireDefault(_scroll); | ||
var _getFullUrl = require('./utils/get-full-url'); | ||
var _getFullUrl2 = _interopRequireDefault(_getFullUrl); | ||
var _getSite2 = require('./utils/get-site'); | ||
var _getSite3 = _interopRequireDefault(_getSite2); | ||
var _getXavierId = require('./utils/get-xavier-id'); | ||
var _getXavierId2 = _interopRequireDefault(_getXavierId); | ||
var _getAbCookie2 = require('./utils/get-ab-cookie'); | ||
var _getAbCookie3 = _interopRequireDefault(_getAbCookie2); | ||
var _getReferrer = require('./utils/get-referrer'); | ||
var _getReferrer2 = _interopRequireDefault(_getReferrer); | ||
var _getDbPlussData = require('./utils/get-db-pluss-data'); | ||
var _getDbPlussData2 = _interopRequireDefault(_getDbPlussData); | ||
var _prevPageview = require('./utils/prev-pageview'); | ||
var _sender = require('./sender/sender'); | ||
var _sender2 = _interopRequireDefault(_sender); | ||
var _configureSender = require('./sender/configure-sender'); | ||
var _articlePreview = require('./utils/article-preview'); | ||
var _articlePreview2 = _interopRequireDefault(_articlePreview); | ||
var _uuid = require('./utils/uuid'); | ||
var _uuid2 = _interopRequireDefault(_uuid); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function /** | ||
* Docs: https://www.iab.com/guidelines/state-of-viewability-transaction-2015/ | ||
* @param {Object} element | ||
*/ | ||
getThreshold(element) { | ||
return element.offsetHeight * element.offsetWidth >= 242500 ? 0.3 : 0.5; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var aller_in_view_1 = __importDefault(require("@soldotno/aller-in-view")); | ||
var blink_1 = __importDefault(require("@aller/blink")); | ||
var throttle_1 = __importDefault(require("lodash/throttle")); | ||
var beforeunload_1 = __importDefault(require("./triggers/beforeunload")); | ||
var click_on_outgoing_link_1 = __importDefault(require("./triggers/click-on-outgoing-link")); | ||
var keydown_1 = __importDefault(require("./triggers/keydown")); | ||
var mousemove_1 = __importDefault(require("./triggers/mousemove")); | ||
var mousedown_1 = __importDefault(require("./triggers/mousedown")); | ||
var visibilitychange_1 = __importDefault(require("./triggers/visibilitychange")); | ||
var page_hide_1 = __importDefault(require("./triggers/page-hide")); | ||
var unload_1 = __importDefault(require("./triggers/unload")); | ||
var scroll_1 = __importDefault(require("./triggers/scroll")); | ||
var get_full_url_1 = __importDefault(require("./utils/get-full-url")); | ||
var get_site_1 = __importDefault(require("./utils/get-site")); | ||
var get_xavier_id_1 = __importDefault(require("./utils/get-xavier-id")); | ||
var get_ab_cookie_1 = __importDefault(require("./utils/get-ab-cookie")); | ||
var get_commercial_segments_1 = __importDefault(require("./utils/get-commercial-segments")); | ||
var get_referrer_1 = __importDefault(require("./utils/get-referrer")); | ||
var get_db_pluss_data_1 = __importDefault(require("./utils/get-db-pluss-data")); | ||
var prev_pageview_1 = require("./utils/prev-pageview"); | ||
var sender_1 = __importDefault(require("./sender/sender")); | ||
var configure_sender_1 = require("./sender/configure-sender"); | ||
var get_sender_config_1 = __importDefault(require("./sender/get-sender-config")); | ||
var article_preview_1 = __importDefault(require("./utils/article-preview")); | ||
var uuid_1 = __importDefault(require("./utils/uuid")); | ||
function getThreshold(element) { | ||
return element.offsetHeight * element.offsetWidth >= 242500 ? 0.3 : 0.5; | ||
} | ||
var LabradorTracker = function () { | ||
function LabradorTracker() { | ||
var _this = this; | ||
_classCallCheck(this, LabradorTracker); | ||
var senderConfigurationParameters = (0, _configureSender.getSenderConfigurationParameters)(); | ||
(0, _configureSender.configureSender)(senderConfigurationParameters); | ||
this.pageView = (0, _uuid2.default)('pageView'); | ||
this.activeTimeTimerId = 0; | ||
this.blink = (0, _blink2.default)({ | ||
send: function send(el) { | ||
return _sender2.default.checkPermissionsBeforeSending(el); | ||
}, | ||
utils: { | ||
getScrollHeight: function getScrollHeight() { | ||
return document.documentElement.scrollHeight; | ||
}, | ||
getClientHeight: function getClientHeight() { | ||
return document.documentElement.clientHeight; | ||
}, | ||
getClientWidth: function getClientWidth() { | ||
return document.documentElement.clientWidth; | ||
}, | ||
getScrollTop: function getScrollTop() { | ||
return document.documentElement.scrollTop; | ||
}, | ||
getSite: function getSite() { | ||
return (0, _getSite3.default)(window.location.hostname); | ||
}, | ||
getUserId: function getUserId() { | ||
return (0, _getXavierId2.default)(); | ||
}, | ||
getAbCookie: function getAbCookie() { | ||
return (0, _getAbCookie3.default)(); | ||
}, | ||
getReferrer: _getReferrer2.default, | ||
getPlussData: _getDbPlussData2.default, | ||
getCmId: function getCmId() { | ||
return window.cmId || null; | ||
} | ||
}, | ||
useDevTools: true | ||
}); | ||
this.inView = (0, _allerInView2.default)(); | ||
this.inView.interval(200); | ||
this.inView.addEventOptions({ | ||
passive: true | ||
}); | ||
(0, _beforeunload2.default)(function () { | ||
_this.blink.sendAllEvents(); | ||
}); | ||
// Initialize the page, and attach the previous pageView | ||
this.blink.pageInit({ | ||
url: window.location.href, | ||
pageView: this.pageView, | ||
previousPageView: (0, _prevPageview.getPageView)((0, _getReferrer2.default)()) | ||
}); | ||
} | ||
_createClass(LabradorTracker, [{ | ||
key: 'trackPageload', | ||
value: function trackPageload() { | ||
this.blink.pageload(window.location.href); | ||
var LabradorTracker = /** @class */ (function () { | ||
function LabradorTracker() { | ||
var _this = this; | ||
configure_sender_1.configureSender(get_sender_config_1.default()); | ||
this.pageView = uuid_1.default('pageView'); | ||
this.activeTimeTimerId = 0; | ||
this.blink = blink_1.default({ | ||
send: function (el) { return sender_1.default.checkPermissionsBeforeSending(el); }, | ||
utils: { | ||
getScrollHeight: function () { return document.documentElement.scrollHeight; }, | ||
getClientHeight: function () { return document.documentElement.clientHeight; }, | ||
getClientWidth: function () { return document.documentElement.clientWidth; }, | ||
getArticleBodyTop: function () { return 0; }, | ||
getArticleBodyHeight: function () { return 0; }, | ||
}, | ||
useDevTools: true, | ||
}); | ||
this.inView = aller_in_view_1.default(); | ||
this.inView.interval(200); | ||
this.inView.addEventOptions({ | ||
passive: true, | ||
}); | ||
beforeunload_1.default(function () { | ||
_this.blink.sendAllEvents(); | ||
}); | ||
// Initialize the page, and attach the previous pageView | ||
this.blink.pageInit({ | ||
url: window.location.href, | ||
pageView: this.pageView, | ||
previousPageView: prev_pageview_1.getPageView(get_referrer_1.default()), | ||
site: get_site_1.default(window.location.hostname), | ||
userId: get_xavier_id_1.default(), | ||
abCookie: get_ab_cookie_1.default(), | ||
commercialSegments: get_commercial_segments_1.default(), | ||
referrer: get_referrer_1.default(), | ||
}); | ||
} | ||
LabradorTracker.prototype.trackPageload = function () { | ||
this.blink.pageLoad({ | ||
url: window.location.href, | ||
cmId: window.cmId || null, | ||
plussData: get_db_pluss_data_1.default(), | ||
}); | ||
}; | ||
/** | ||
@@ -180,19 +83,16 @@ * Track a specify element, logs to GAP, uses the standard ads rules to see if it is inscreen. | ||
*/ | ||
}, { | ||
key: 'trackAdInscreen', | ||
value: function trackAdInscreen(selector) { | ||
var _this2 = this; | ||
document.querySelectorAll(selector).forEach(function (element) { | ||
if (element.id !== undefined && element.id !== '') { | ||
_this2.inView('#' + element.id, { threshold: getThreshold(element) }).on('enter', function () { | ||
_this2.blink.adScreenEnter(element.id); | ||
}).on('exit', function () { | ||
_this2.blink.adScreenExit(element.id); | ||
}); | ||
} | ||
}); | ||
} | ||
LabradorTracker.prototype.trackAdInscreen = function (selector) { | ||
var _this = this; | ||
document.querySelectorAll(selector).forEach(function (element) { | ||
if (element.id !== undefined && element.id !== '') { | ||
_this.inView("#" + element.id, { threshold: getThreshold(element) }) | ||
.on('enter', function () { | ||
_this.blink.adScreenEnter(element.id); | ||
}) | ||
.on('exit', function () { | ||
_this.blink.adScreenExit(element.id); | ||
}); | ||
} | ||
}); | ||
}; | ||
/** | ||
@@ -203,134 +103,117 @@ * Track elements based on a selector, logs to GAP, | ||
*/ | ||
}, { | ||
key: 'trackAdInscreen0', | ||
value: function trackAdInscreen0(selector) { | ||
var _this3 = this; | ||
this.inView(selector).on('enter', function (domElement) { | ||
_this3.blink.adScreenEnter0(domElement.getAttribute('id')); | ||
}).on('exit', function (domElement) { | ||
_this3.blink.adScreenExit0(domElement.getAttribute('id')); | ||
}); | ||
} | ||
}, { | ||
key: 'trackAdDFP', | ||
value: function trackAdDFP() { | ||
var _this4 = this; | ||
window.googletag = window.googletag || {}; | ||
window.googletag.cmd = window.googletag.cmd || []; | ||
window.googletag.cmd.push(function () { | ||
window.googletag.pubads().addEventListener('impressionViewable', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
_this4.blink.dfpImpressionViewable({ id: elementId }); | ||
LabradorTracker.prototype.trackAdInscreen0 = function (selector) { | ||
var _this = this; | ||
this.inView(selector) | ||
.on('enter', function (domElement) { | ||
_this.blink.adScreenEnter0(domElement.getAttribute('id')); | ||
}) | ||
.on('exit', function (domElement) { | ||
_this.blink.adScreenExit0(domElement.getAttribute('id')); | ||
}); | ||
window.googletag.pubads().addEventListener('slotRenderEnded', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
_this4.blink.dfpSlotRenderEnded({ | ||
adUnitPath: event.slot.getAdUnitPath(), | ||
advertiserId: event.advertiserId, | ||
campaignId: event.campaignId, | ||
creativeId: event.creativeId, | ||
id: elementId, | ||
lineItemId: event.lineItemId, | ||
size: event.size, | ||
sourceAgnosticCreativeId: event.sourceAgnosticCreativeId, | ||
sourceAgnosticLineItemId: event.sourceAgnosticLineItemId, | ||
bidder: event.slot.getTargeting('hb_bidder').join(',') | ||
}); | ||
}; | ||
LabradorTracker.prototype.trackAdDFP = function () { | ||
var _this = this; | ||
window.googletag = window.googletag || {}; | ||
window.googletag.cmd = window.googletag.cmd || []; | ||
window.googletag.cmd.push(function () { | ||
window.googletag | ||
.pubads() | ||
.addEventListener('impressionViewable', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
_this.blink.dfpImpressionViewable({ | ||
id: elementId, | ||
scrollTop: document.documentElement.scrollTop, | ||
}); | ||
}); | ||
window.googletag | ||
.pubads() | ||
.addEventListener('slotRenderEnded', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
_this.blink.dfpSlotRenderEnded({ | ||
adUnitPath: event.slot.getAdUnitPath(), | ||
advertiserId: event.advertiserId, | ||
campaignId: event.campaignId, | ||
creativeId: event.creativeId, | ||
id: elementId, | ||
lineItemId: event.lineItemId, | ||
size: event.size, | ||
sourceAgnosticCreativeId: event.sourceAgnosticCreativeId, | ||
sourceAgnosticLineItemId: event.sourceAgnosticLineItemId, | ||
bidder: event.slot.getTargeting('hb_bidder').join(','), | ||
scrollTop: document.documentElement.scrollTop, | ||
}); | ||
}); | ||
window.googletag | ||
.pubads() | ||
.addEventListener('slotOnload', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
var name = event.slot.getTargeting('pos')[0]; | ||
_this.blink.dfpSlotOnload({ | ||
id: elementId, | ||
name: name, | ||
scrollTop: document.documentElement.scrollTop, | ||
}); | ||
}); | ||
}); | ||
window.googletag.pubads().addEventListener('slotOnload', function (event) { | ||
var elementId = event.slot.getSlotElementId(); | ||
var name = event.slot.getTargeting('pos')[0]; | ||
_this4.blink.dfpSlotOnload({ | ||
id: elementId, | ||
name: name | ||
}); | ||
}; | ||
LabradorTracker.prototype.trackLinkClicks = function () { | ||
var _this = this; | ||
click_on_outgoing_link_1.default(function (_event, element) { | ||
var url = get_full_url_1.default(element.getAttribute('href'), window.location); | ||
_this.blink.click(url); | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'trackLinkClicks', | ||
value: function trackLinkClicks() { | ||
var _this5 = this; | ||
(0, _clickOnOutgoingLink2.default)(function (_event, element) { | ||
var url = (0, _getFullUrl2.default)(element.getAttribute('href'), window.location); | ||
_this5.blink.click(url); | ||
}); | ||
} | ||
}, { | ||
key: '_resetActiveTimer', | ||
value: function _resetActiveTimer(url) { | ||
var _this6 = this; | ||
clearTimeout(this.activeTimeTimerId); | ||
this.activeTimeTimerId = setTimeout(function () { | ||
return _this6.blink.articleActivityPause(url); | ||
}, 10000); | ||
} | ||
}, { | ||
key: 'trackActiveTime', | ||
value: function trackActiveTime() { | ||
var _this7 = this; | ||
var url = LabradorTracker._getCurrentUrl(); | ||
this._resetActiveTimer(url); | ||
var throttledStart = (0, _throttle2.default)(function () { | ||
_this7._resetActiveTimer(url); | ||
_this7.blink.articleActivityStart(url); | ||
// Store the current pageView so we can pick it up on following pages | ||
(0, _prevPageview.setPageView)(window.location.href, _this7.pageView); | ||
}, 2000); | ||
var pause = function pause() { | ||
return _this7.blink.articleActivityPause(url); | ||
}; | ||
var stop = function stop() { | ||
return _this7.blink.articleActivityStop(url); | ||
}; | ||
(0, _mousedown2.default)(throttledStart); | ||
(0, _keydown2.default)(throttledStart); | ||
(0, _scroll2.default)(throttledStart); | ||
(0, _mousemove2.default)(throttledStart); | ||
(0, _visibilitychange2.default)(pause); | ||
(0, _clickOnOutgoingLink2.default)(stop); | ||
(0, _unload2.default)(stop); | ||
(0, _beforeunload2.default)(stop); | ||
(0, _pageHide2.default)(stop); | ||
} | ||
}, { | ||
key: 'trackArticleImpressions', | ||
value: function trackArticleImpressions(selector) { | ||
var _this8 = this; | ||
this.inView(selector, { threshold: 0.5 }).on('enter', function (domElement) { | ||
var preview = new _articlePreview2.default(domElement, window.location); | ||
_this8.blink.articlePreviewScreenEnter({ | ||
url: preview.url, | ||
title: preview.title, | ||
height: preview.height, | ||
width: preview.width, | ||
personalizationSystemUsed: preview.personalizationSystemUsed, | ||
personalizationParametersRequested: preview.personalizationParametersRequested | ||
}; | ||
LabradorTracker.prototype._resetActiveTimer = function (url) { | ||
var _this = this; | ||
clearTimeout(this.activeTimeTimerId); | ||
this.activeTimeTimerId = window.setTimeout(function () { return _this.blink.articleActivityPause(url); }, 10000); | ||
}; | ||
LabradorTracker._getCurrentUrl = function () { | ||
var el = document.head.querySelector('meta[property="og:url"]'); | ||
return (el && el.getAttribute('content')) || window.location.href; | ||
}; | ||
LabradorTracker.prototype.trackActiveTime = function () { | ||
var _this = this; | ||
var url = LabradorTracker._getCurrentUrl(); | ||
this._resetActiveTimer(url); | ||
var throttledStart = throttle_1.default(function () { | ||
_this._resetActiveTimer(url); | ||
_this.blink.articleActivityStart(url); | ||
// Store the current pageView so we can pick it up on following pages | ||
prev_pageview_1.setPageView(window.location.href, _this.pageView); | ||
}, 2000); | ||
var pause = function () { return _this.blink.articleActivityPause(url); }; | ||
var stop = function () { return _this.blink.articleActivityStop(url); }; | ||
mousedown_1.default(throttledStart); | ||
keydown_1.default(throttledStart); | ||
scroll_1.default(throttledStart); | ||
mousemove_1.default(throttledStart); | ||
visibilitychange_1.default(pause); | ||
click_on_outgoing_link_1.default(stop); | ||
unload_1.default(stop); | ||
beforeunload_1.default(stop); | ||
page_hide_1.default(stop); | ||
}; | ||
LabradorTracker.prototype.trackArticleImpressions = function (selector) { | ||
var _this = this; | ||
this.inView(selector, { threshold: 0.5 }) | ||
.on('enter', function (domElement) { | ||
var preview = new article_preview_1.default(domElement, window.location); | ||
_this.blink.articlePreviewScreenEnter({ | ||
url: preview.url, | ||
title: preview.title, | ||
height: preview.height, | ||
width: preview.width, | ||
personalizationSystemUsed: preview.personalizationSystemUsed, | ||
personalizationParametersRequested: preview.personalizationParametersRequested, | ||
}); | ||
}) | ||
.on('exit', function (domElement) { | ||
var url = get_full_url_1.default(domElement.querySelector('a').getAttribute('href'), window.location); | ||
_this.blink.articlePreviewScreenExit(url); | ||
}); | ||
}).on('exit', function (domElement) { | ||
var url = (0, _getFullUrl2.default)(domElement.querySelector('a').getAttribute('href'), window.location); | ||
_this8.blink.articlePreviewScreenExit(url); | ||
}); | ||
} | ||
}], [{ | ||
key: '_getCurrentUrl', | ||
value: function _getCurrentUrl() { | ||
var el = document.head.querySelector('meta[property="og:url"]'); | ||
return el && el.getAttribute('content') || window.location.href; | ||
} | ||
}]); | ||
return LabradorTracker; | ||
}(); | ||
exports.default = LabradorTracker; | ||
}; | ||
return LabradorTracker; | ||
}()); | ||
exports.default = LabradorTracker; | ||
//# sourceMappingURL=main.js.map |
@@ -1,110 +0,46 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.configureSender = configureSender; | ||
exports.getSenderConfigurationParameters = getSenderConfigurationParameters; | ||
var _includes = require('lodash/includes'); | ||
var _includes2 = _interopRequireDefault(_includes); | ||
var _visibilitychange = require('../triggers/visibilitychange'); | ||
var _visibilitychange2 = _interopRequireDefault(_visibilitychange); | ||
var _clickOnOutgoingLink = require('../triggers/click-on-outgoing-link'); | ||
var _clickOnOutgoingLink2 = _interopRequireDefault(_clickOnOutgoingLink); | ||
var _pageHide = require('../triggers/page-hide'); | ||
var _pageHide2 = _interopRequireDefault(_pageHide); | ||
var _beforeunload = require('../triggers/beforeunload'); | ||
var _beforeunload2 = _interopRequireDefault(_beforeunload); | ||
var _unload = require('../triggers/unload'); | ||
var _unload2 = _interopRequireDefault(_unload); | ||
var _sender = require('./sender'); | ||
var _sender2 = _interopRequireDefault(_sender); | ||
var _cmp = require('../gdpr/cmp'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function configureSender(_ref) { | ||
var sendInterval = _ref.sendInterval, | ||
batchLimit = _ref.batchLimit, | ||
batchInterval = _ref.batchInterval, | ||
sendUrl = _ref.sendUrl; | ||
function sendWithBeacon(events) { | ||
var data = JSON.stringify(events); | ||
if ('sendBeacon' in navigator) { | ||
window.navigator.sendBeacon(sendUrl, data); | ||
} else { | ||
var req = new XMLHttpRequest(); | ||
req.open('POST', sendUrl, true); | ||
req.setRequestHeader('Content-Type', 'application/json'); | ||
req.send(data); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var visibilitychange_1 = __importDefault(require("../triggers/visibilitychange")); | ||
var click_on_outgoing_link_1 = __importDefault(require("../triggers/click-on-outgoing-link")); | ||
var page_hide_1 = __importDefault(require("../triggers/page-hide")); | ||
var beforeunload_1 = __importDefault(require("../triggers/beforeunload")); | ||
var unload_1 = __importDefault(require("../triggers/unload")); | ||
var sender_1 = __importDefault(require("./sender")); | ||
var cmp_1 = require("../gdpr/cmp"); | ||
function configureSender(_a) { | ||
var sendInterval = _a.sendInterval, batchLimit = _a.batchLimit, batchInterval = _a.batchInterval, sendUrl = _a.sendUrl; | ||
function sendWithBeacon(events) { | ||
var data = JSON.stringify(events); | ||
if ('sendBeacon' in navigator) { | ||
window.navigator.sendBeacon(sendUrl, data); | ||
} | ||
else { | ||
var req = new XMLHttpRequest(); | ||
req.open('POST', sendUrl, true); | ||
req.setRequestHeader('Content-Type', 'application/json'); | ||
req.send(data); | ||
} | ||
} | ||
} | ||
// Configure batching | ||
if (batchInterval) { | ||
setInterval(function () { | ||
if (_sender2.default.pendingEvents.length > batchLimit) { | ||
_sender2.default.sendAllNow('BATCH'); | ||
} | ||
}, batchInterval); | ||
} | ||
// Configure normal send interval | ||
setInterval(function () { | ||
return _sender2.default.sendAllNow('IDLE'); | ||
}, sendInterval); | ||
_sender2.default.configureSend(sendWithBeacon, _cmp.hasEveryConsent); | ||
// Configure event handlers | ||
(0, _visibilitychange2.default)(function () { | ||
return _sender2.default.sendAllNow('VISIBILITY CHANGE'); | ||
}); | ||
(0, _clickOnOutgoingLink2.default)(function () { | ||
return _sender2.default.sendAllNow('LINK CLICK'); | ||
}); | ||
(0, _pageHide2.default)(function () { | ||
return _sender2.default.sendAllNow('PAGE HIDE'); | ||
}); | ||
(0, _beforeunload2.default)(function () { | ||
return _sender2.default.sendAllNow('BEFORE UNLOAD'); | ||
}); | ||
(0, _unload2.default)(function () { | ||
return _sender2.default.sendAllNow('UNLOAD'); | ||
}); | ||
// Configure batching | ||
if (batchInterval) { | ||
setInterval(function () { | ||
if (sender_1.default.pendingEvents.length > batchLimit) { | ||
sender_1.default.sendAllNow(); | ||
} | ||
}, batchInterval); | ||
} | ||
// Configure normal send interval | ||
setInterval(function () { return sender_1.default.sendAllNow(); }, sendInterval); | ||
sender_1.default.configureSend(sendWithBeacon, cmp_1.hasEveryConsent); | ||
// Configure event handlers | ||
visibilitychange_1.default(function () { return sender_1.default.sendAllNow(); }); | ||
click_on_outgoing_link_1.default(function () { return sender_1.default.sendAllNow(); }); | ||
page_hide_1.default(function () { return sender_1.default.sendAllNow(); }); | ||
beforeunload_1.default(function () { return sender_1.default.sendAllNow(); }); | ||
unload_1.default(function () { return sender_1.default.sendAllNow(); }); | ||
} | ||
function getSenderConfigurationParameters() { | ||
var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : navigator.userAgent; | ||
if ((0, _includes2.default)(userAgent, '_app_')) { | ||
return { | ||
sendInterval: 2000, | ||
batchLimit: 0, | ||
batchInterval: 0, | ||
sendUrl: 'https://aas.medialaben.no/a/' | ||
}; | ||
} | ||
return { | ||
sendInterval: 10000, | ||
batchLimit: 3, | ||
batchInterval: 3000, | ||
sendUrl: 'https://aas.medialaben.no/a/' | ||
}; | ||
} | ||
exports.configureSender = configureSender; | ||
//# sourceMappingURL=configure-sender.js.map |
@@ -1,95 +0,69 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.TestableSender = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _store = require('./store'); | ||
var _store2 = _interopRequireDefault(_store); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Sender = function () { | ||
function Sender() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
pendingEvents = _ref.pendingEvents, | ||
sentEvents = _ref.sentEvents, | ||
send = _ref.send, | ||
checkConsent = _ref.checkConsent; | ||
_classCallCheck(this, Sender); | ||
this.send = send; | ||
this.pendingStore = new _store2.default('id'); | ||
this.pendingStore.add(pendingEvents); | ||
this.sentStore = new _store2.default('id'); | ||
this.sentStore.add(sentEvents); | ||
this.checkConsent = checkConsent; | ||
} | ||
_createClass(Sender, [{ | ||
key: 'configureSend', | ||
value: function configureSend(send, checkConsent) { | ||
this.send = send; | ||
this.checkConsent = checkConsent; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var store_1 = __importDefault(require("./store")); | ||
var Sender = /** @class */ (function () { | ||
function Sender(_a) { | ||
var pendingEvents = _a.pendingEvents, sentEvents = _a.sentEvents, send = _a.send, checkConsent = _a.checkConsent; | ||
this.send = send; | ||
this.pendingStore = new store_1.default('id'); | ||
this.pendingStore.add(pendingEvents); | ||
this.sentStore = new store_1.default('id'); | ||
this.sentStore.add(sentEvents); | ||
this.checkConsent = checkConsent; | ||
} | ||
}, { | ||
key: 'sendAllNow', | ||
value: function sendAllNow() { | ||
if (this.pendingEvents.length === 0) { | ||
return []; | ||
} | ||
var events = this.pendingEvents.slice(0); | ||
this.sentStore.add(this.pendingEvents); | ||
this.pendingStore.flush(); | ||
this.send(events); | ||
return events; | ||
} | ||
}, { | ||
key: 'sendWhenBefitting', | ||
value: function sendWhenBefitting() { | ||
var _this = this; | ||
var events = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var notAlreadySent = events.filter(function (event) { | ||
return !_this.sentStore.contains(event); | ||
}); | ||
this.pendingStore.add(notAlreadySent); | ||
} | ||
}, { | ||
key: 'checkPermissionsBeforeSending', | ||
value: function checkPermissionsBeforeSending() { | ||
var _this2 = this; | ||
var events = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
this.checkConsent(function (hasConsent) { | ||
if (hasConsent) { | ||
_this2.sendWhenBefitting(events); | ||
Sender.prototype.configureSend = function (send, checkConsent) { | ||
this.send = send; | ||
this.checkConsent = checkConsent; | ||
}; | ||
Object.defineProperty(Sender.prototype, "pendingEvents", { | ||
get: function () { | ||
return this.pendingStore.events; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sender.prototype, "sentEvents", { | ||
get: function () { | ||
return this.sentStore.events; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Sender.prototype.sendAllNow = function () { | ||
if (this.pendingEvents.length === 0) { | ||
return []; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: 'pendingEvents', | ||
get: function get() { | ||
return this.pendingStore.events; | ||
} | ||
}, { | ||
key: 'sentEvents', | ||
get: function get() { | ||
return this.sentStore.events; | ||
} | ||
}]); | ||
return Sender; | ||
}(); | ||
var events = this.pendingEvents.slice(0); | ||
this.sentStore.add(this.pendingEvents); | ||
this.pendingStore.flush(); | ||
this.send(events); | ||
return events; | ||
}; | ||
Sender.prototype.sendWhenBefitting = function (events) { | ||
var _this = this; | ||
if (events === void 0) { events = []; } | ||
var notAlreadySent = events.filter(function (event) { return !_this.sentStore.contains(event); }); | ||
this.pendingStore.add(notAlreadySent); | ||
}; | ||
Sender.prototype.checkPermissionsBeforeSending = function (events) { | ||
var _this = this; | ||
if (events === void 0) { events = []; } | ||
this.checkConsent(function (hasConsent) { | ||
if (hasConsent) { | ||
_this.sendWhenBefitting(events); | ||
} | ||
}); | ||
}; | ||
return Sender; | ||
}()); | ||
exports.TestableSender = Sender; | ||
exports.default = new Sender(); | ||
exports.default = new Sender({ | ||
pendingEvents: [], | ||
sentEvents: [], | ||
send: null, | ||
checkConsent: null, | ||
}); | ||
//# sourceMappingURL=sender.js.map |
@@ -1,74 +0,45 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _isEqual = require('lodash/isEqual'); | ||
var _isEqual2 = _interopRequireDefault(_isEqual); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Store = function () { | ||
function Store(idKey) { | ||
_classCallCheck(this, Store); | ||
this.idKey = idKey; | ||
this.data = {}; | ||
} | ||
_createClass(Store, [{ | ||
key: 'add', | ||
value: function add() { | ||
var _this = this; | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
data.forEach(function (entry) { | ||
return _this.update(entry); | ||
}); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isEqual_1 = __importDefault(require("lodash/isEqual")); | ||
var Store = /** @class */ (function () { | ||
function Store(idKey) { | ||
this.idKey = idKey; | ||
this.data = {}; | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update(entry) { | ||
var id = entry[this.idKey]; | ||
if (!id) { | ||
return; | ||
} | ||
this.data[id] = entry; | ||
} | ||
}, { | ||
key: 'contains', | ||
value: function contains(entry) { | ||
var id = entry[this.idKey]; | ||
if (!id || !this.data[id]) { | ||
return false; | ||
} | ||
return (0, _isEqual2.default)(entry, this.data[id]); | ||
} | ||
}, { | ||
key: 'flush', | ||
value: function flush() { | ||
this.data = {}; | ||
} | ||
}, { | ||
key: 'events', | ||
get: function get() { | ||
var _this2 = this; | ||
return Object.keys(this.data).map(function (id) { | ||
return _this2.data[id]; | ||
}); | ||
} | ||
}]); | ||
return Store; | ||
}(); | ||
exports.default = Store; | ||
Store.prototype.add = function (data) { | ||
var _this = this; | ||
if (data === void 0) { data = []; } | ||
data.forEach(function (entry) { return _this.update(entry); }); | ||
}; | ||
Store.prototype.update = function (entry) { | ||
var id = entry[this.idKey]; | ||
if (!id) { | ||
return; | ||
} | ||
this.data[id] = entry; | ||
}; | ||
Store.prototype.contains = function (entry) { | ||
var id = entry[this.idKey]; | ||
if (!id || !this.data[id]) { | ||
return false; | ||
} | ||
return isEqual_1.default(entry, this.data[id]); | ||
}; | ||
Store.prototype.flush = function () { | ||
this.data = {}; | ||
}; | ||
Object.defineProperty(Store.prototype, "events", { | ||
get: function () { | ||
var _this = this; | ||
return Object.keys(this.data).map(function (id) { return _this.data[id]; }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Store; | ||
}()); | ||
exports.default = Store; | ||
//# sourceMappingURL=store.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnUnload; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -14,3 +8,5 @@ * @param {function} callback | ||
function addEventListenerOnUnload(callback) { | ||
(0, _addListener.addListenerAggregated)('beforeunload', callback); | ||
} | ||
add_listener_1.addListenerAggregated('beforeunload', callback); | ||
} | ||
exports.default = addEventListenerOnUnload; | ||
//# sourceMappingURL=beforeunload.js.map |
@@ -1,20 +0,9 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnOutgoingLink; | ||
var _includes = require('lodash/includes'); | ||
var _includes2 = _interopRequireDefault(_includes); | ||
var _debounce = require('lodash/debounce'); | ||
var _debounce2 = _interopRequireDefault(_debounce); | ||
var _addListener = require('../utils/add-listener'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var includes_1 = __importDefault(require("lodash/includes")); | ||
var debounce_1 = __importDefault(require("lodash/debounce")); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -25,9 +14,7 @@ * @param node - DOM node | ||
function getParentIfA(node) { | ||
if (!node || !node.parentNode) { | ||
return null; | ||
} | ||
return node.parentNode.tagName === 'A' ? node.parentNode : null; | ||
if (!node || !node.parentNode) { | ||
return null; | ||
} | ||
return node.parentNode.tagName === 'A' ? node.parentNode : null; | ||
} | ||
/** | ||
@@ -38,27 +25,20 @@ * Figure out if the click was on a link and send report if so. | ||
function isClickOnLinkClick(e) { | ||
var linkElement = e.target.tagName === 'A' ? e.target : null; | ||
if (!linkElement) { | ||
linkElement = getParentIfA(e.target); | ||
} | ||
if (!linkElement) { | ||
linkElement = getParentIfA(e.target.parentNode); | ||
} | ||
if (!linkElement && e.target.parentNode) { | ||
linkElement = getParentIfA(e.target.parentNode.parentNode); | ||
} | ||
if (linkElement) { | ||
var href = linkElement.getAttribute('href'); | ||
if (href && (0, _includes2.default)(href, '/')) { | ||
return { isLink: true, element: linkElement }; | ||
var linkElement = e.target.tagName === 'A' ? e.target : null; | ||
if (!linkElement) { | ||
linkElement = getParentIfA(e.target); | ||
} | ||
} | ||
return { isLink: false }; | ||
if (!linkElement) { | ||
linkElement = getParentIfA(e.target.parentNode); | ||
} | ||
if (!linkElement && e.target.parentNode) { | ||
linkElement = getParentIfA(e.target.parentNode.parentNode); | ||
} | ||
if (linkElement) { | ||
var href = linkElement.getAttribute('href'); | ||
if (href && includes_1.default(href, '/')) { | ||
return { isLink: true, element: linkElement }; | ||
} | ||
} | ||
return { isLink: false }; | ||
} | ||
/** | ||
@@ -69,17 +49,20 @@ * EventLisener that triggers on outbounding links. | ||
function addEventListenerOnOutgoingLink(callback) { | ||
var lastUrl = ''; | ||
var resetUrl = (0, _debounce2.default)(function () { | ||
lastUrl = ''; | ||
}, 100); | ||
function sendEventIfLink(event) { | ||
var clickData = isClickOnLinkClick(event); | ||
if (clickData.isLink && clickData.element.getAttribute('href') !== lastUrl) { | ||
lastUrl = clickData.element.getAttribute('href'); | ||
callback(event, clickData.element); | ||
resetUrl(); | ||
var lastUrl = ''; | ||
var resetUrl = debounce_1.default(function () { | ||
lastUrl = ''; | ||
}, 100); | ||
function sendEventIfLink(event) { | ||
var clickData = isClickOnLinkClick(event); | ||
if (clickData.isLink && | ||
clickData.element.getAttribute('href') !== lastUrl) { | ||
lastUrl = clickData.element.getAttribute('href'); | ||
callback(event, clickData.element); | ||
resetUrl(); | ||
} | ||
} | ||
} | ||
(0, _addListener.addListenerAggregated)('contextmenu', sendEventIfLink); | ||
(0, _addListener.addListenerAggregated)('click', sendEventIfLink); | ||
(0, _addListener.addListenerAggregated)('mousedown', sendEventIfLink); | ||
} | ||
add_listener_1.addListenerAggregated('contextmenu', sendEventIfLink); | ||
add_listener_1.addListenerAggregated('click', sendEventIfLink); | ||
add_listener_1.addListenerAggregated('mousedown', sendEventIfLink); | ||
} | ||
exports.default = addEventListenerOnOutgoingLink; | ||
//# sourceMappingURL=click-on-outgoing-link.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnKeydown; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -15,3 +9,5 @@ * Adds a function to the eventLisener connected to keydown | ||
function addEventListenerOnKeydown(callback) { | ||
(0, _addListener.addListenerAggregated)('keydown', callback); | ||
} | ||
add_listener_1.addListenerAggregated('keydown', callback); | ||
} | ||
exports.default = addEventListenerOnKeydown; | ||
//# sourceMappingURL=keydown.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnLoad; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -15,3 +9,5 @@ * | ||
function addEventListenerOnLoad(callback) { | ||
(0, _addListener.addListenerAggregated)('load', callback); | ||
} | ||
add_listener_1.addListenerAggregated('load', callback); | ||
} | ||
exports.default = addEventListenerOnLoad; | ||
//# sourceMappingURL=load.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnMouseDown; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -15,3 +9,5 @@ * EventLisener that triggers on outbounding links. | ||
function addEventListenerOnMouseDown(callback) { | ||
(0, _addListener.addListenerAggregated)('mousedown', callback); | ||
} | ||
add_listener_1.addListenerAggregated('mousedown', callback); | ||
} | ||
exports.default = addEventListenerOnMouseDown; | ||
//# sourceMappingURL=mousedown.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnMouseMove; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -15,3 +9,5 @@ * EventLisener that triggers on outbounding links. | ||
function addEventListenerOnMouseMove(callback) { | ||
(0, _addListener.addListenerAggregated)('mousemove', callback); | ||
} | ||
add_listener_1.addListenerAggregated('mousemove', callback); | ||
} | ||
exports.default = addEventListenerOnMouseMove; | ||
//# sourceMappingURL=mousemove.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnPagehide; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -15,3 +9,5 @@ * EventLisener that triggers on outbounding links. | ||
function addEventListenerOnPagehide(callback) { | ||
(0, _addListener.addListenerAggregated)('pagehide', callback); | ||
} | ||
add_listener_1.addListenerAggregated('pagehide', callback); | ||
} | ||
exports.default = addEventListenerOnPagehide; | ||
//# sourceMappingURL=page-hide.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnScroll; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -14,3 +8,5 @@ * @param {function} callback | ||
function addEventListenerOnScroll(callback) { | ||
(0, _addListener.addListenerAggregated)('scroll', callback); | ||
} | ||
add_listener_1.addListenerAggregated('scroll', callback); | ||
} | ||
exports.default = addEventListenerOnScroll; | ||
//# sourceMappingURL=scroll.js.map |
@@ -1,10 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnUnload; | ||
var _addListener = require('../utils/add-listener'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
/** | ||
@@ -14,3 +8,5 @@ * @param {function} callback | ||
function addEventListenerOnUnload(callback) { | ||
(0, _addListener.addListenerAggregated)('unload', callback); | ||
} | ||
add_listener_1.addListenerAggregated('unload', callback); | ||
} | ||
exports.default = addEventListenerOnUnload; | ||
//# sourceMappingURL=unload.js.map |
@@ -1,16 +0,8 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addEventListenerOnVisibilityChangeToHide; | ||
var _addListener = require('../utils/add-listener'); | ||
var _getHiddenStatus = require('../utils/get-hidden-status'); | ||
var _getHiddenStatus2 = _interopRequireDefault(_getHiddenStatus); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var add_listener_1 = require("../utils/add-listener"); | ||
var get_hidden_status_1 = __importDefault(require("../utils/get-hidden-status")); | ||
/** | ||
@@ -20,8 +12,10 @@ * @param {function} callback | ||
function addEventListenerOnVisibilityChangeToHide(callback) { | ||
var hidden = (0, _getHiddenStatus2.default)(); | ||
(0, _addListener.addListenerAggregated)(hidden.prefix + 'visibilitychange', function (event) { | ||
if (typeof document !== 'undefined' && document.hidden === true) { | ||
callback(event); | ||
} | ||
}); | ||
} | ||
var hidden = get_hidden_status_1.default(); | ||
add_listener_1.addListenerAggregated(hidden.prefix + "visibilitychange", function (event) { | ||
if (typeof document !== 'undefined' && document.hidden === true) { | ||
callback(event); | ||
} | ||
}); | ||
} | ||
exports.default = addEventListenerOnVisibilityChangeToHide; | ||
//# sourceMappingURL=visibilitychange.js.map |
@@ -1,19 +0,8 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = addListener; | ||
exports.addListenerAggregated = addListenerAggregated; | ||
var _throttle = require('lodash/throttle'); | ||
var _throttle2 = _interopRequireDefault(_throttle); | ||
var _includes = require('lodash/includes'); | ||
var _includes2 = _interopRequireDefault(_includes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var throttle_1 = __importDefault(require("lodash/throttle")); | ||
var includes_1 = __importDefault(require("lodash/includes")); | ||
/** | ||
@@ -23,3 +12,2 @@ * The callback for when an event occurs. | ||
*/ | ||
/** | ||
@@ -29,3 +17,2 @@ * {object} one key for every eventType. the value is a array of cb to be run for that event | ||
var callbacksPrEventType = {}; | ||
/** | ||
@@ -35,3 +22,2 @@ * {list} the events that we have checked that should be attached to the window object | ||
var windowEvents = ['beforeunload', 'unload', 'pagehide']; | ||
/** | ||
@@ -47,18 +33,15 @@ * Adds an event listener. Try to use addListenerAggreagted | ||
*/ | ||
function addListener(evt, cb) { | ||
var thr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100; | ||
var throttledCallback = (0, _throttle2.default)(cb, thr); | ||
if ((0, _includes2.default)(windowEvents, evt)) { | ||
window.addEventListener(evt, throttledCallback, { passive: true }); | ||
} else if (document.addEventListener) { | ||
document.addEventListener(evt, throttledCallback, { passive: true }); | ||
} else if (window.attachEvent) { | ||
window.attachEvent('on' + evt, throttledCallback); | ||
} | ||
// Need the exact function if we want to remove the listener. | ||
return throttledCallback; | ||
function addListener(evt, cb, thr) { | ||
if (thr === void 0) { thr = 100; } | ||
var throttledCallback = throttle_1.default(cb, thr); | ||
if (includes_1.default(windowEvents, evt)) { | ||
window.addEventListener(evt, throttledCallback, { passive: true }); | ||
} | ||
else if (document.addEventListener) { | ||
document.addEventListener(evt, throttledCallback, { passive: true }); | ||
} | ||
// Need the exact function if we want to remove the listener. | ||
return throttledCallback; | ||
} | ||
exports.default = addListener; | ||
/** | ||
@@ -73,15 +56,17 @@ * If you know that you do not need to remove the EventListener, this is the Listener to use. | ||
function addListenerAggregated(evt, cb) { | ||
if (evt in callbacksPrEventType) { | ||
callbacksPrEventType[evt].push(cb); | ||
} else { | ||
callbacksPrEventType[evt] = []; | ||
callbacksPrEventType[evt].push(cb); | ||
var runCallbacks = function runCallbacks(event) { | ||
callbacksPrEventType[evt].forEach(function (eventL) { | ||
eventL(event); | ||
}); | ||
}; | ||
addListener(evt, runCallbacks); | ||
} | ||
} | ||
if (evt in callbacksPrEventType) { | ||
callbacksPrEventType[evt].push(cb); | ||
} | ||
else { | ||
callbacksPrEventType[evt] = []; | ||
callbacksPrEventType[evt].push(cb); | ||
var runCallbacks = function (event) { | ||
callbacksPrEventType[evt].forEach(function (eventL) { | ||
eventL(event); | ||
}); | ||
}; | ||
addListener(evt, runCallbacks); | ||
} | ||
} | ||
exports.addListenerAggregated = addListenerAggregated; | ||
//# sourceMappingURL=add-listener.js.map |
@@ -1,78 +0,77 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _getFullUrl = require('./get-full-url'); | ||
var _getFullUrl2 = _interopRequireDefault(_getFullUrl); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var get_full_url_1 = __importDefault(require("./get-full-url")); | ||
/** | ||
* Wraps the DOMElement of a plug on the frontpage and extracts metadata. | ||
*/ | ||
var ArticlePreview = function () { | ||
function ArticlePreview(domElement, location) { | ||
_classCallCheck(this, ArticlePreview); | ||
this.domElement = domElement; | ||
this.location = location || { | ||
origin: 'http://location.unknown', | ||
protocol: 'http:' | ||
}; | ||
} | ||
_createClass(ArticlePreview, [{ | ||
key: 'height', | ||
get: function get() { | ||
return parseInt(this.domElement.getBoundingClientRect().height, 10); | ||
var ArticlePreview = /** @class */ (function () { | ||
function ArticlePreview(domElement, location) { | ||
this.domElement = domElement; | ||
this.location = location || { | ||
origin: 'http://location.unknown', | ||
protocol: 'http:', | ||
}; | ||
} | ||
}, { | ||
key: 'width', | ||
get: function get() { | ||
return parseInt(this.domElement.getBoundingClientRect().width, 10); | ||
} | ||
}, { | ||
key: 'personalizationParametersRequested', | ||
get: function get() { | ||
return this.domElement.getAttribute('data-cxence_widget'); | ||
} | ||
}, { | ||
key: 'personalizationSystemUsed', | ||
get: function get() { | ||
return this.domElement.getAttribute('data-cxense_tag'); | ||
} | ||
}, { | ||
key: 'title', | ||
get: function get() { | ||
// Handle lommelegen question special case | ||
if (this.domElement.querySelector('h4')) { | ||
return this.domElement.querySelector('h4').textContent.trim(); | ||
} | ||
// Handle dinside test special case | ||
if (this.domElement.querySelector('h3[itemprop="headline"]')) { | ||
return this.domElement.querySelector('h3[itemprop="headline"]').textContent.trim(); | ||
} | ||
if (this.domElement.querySelector('.headline')) { | ||
return this.domElement.querySelector('.headline').textContent.trim(); | ||
} | ||
return null; | ||
} | ||
}, { | ||
key: 'url', | ||
get: function get() { | ||
var href = this.domElement.querySelector('a').getAttribute('href'); | ||
return (0, _getFullUrl2.default)(href, this.location); | ||
} | ||
}]); | ||
return ArticlePreview; | ||
}(); | ||
exports.default = ArticlePreview; | ||
Object.defineProperty(ArticlePreview.prototype, "height", { | ||
get: function () { | ||
return Math.floor(this.domElement.getBoundingClientRect().height); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ArticlePreview.prototype, "width", { | ||
get: function () { | ||
return Math.floor(this.domElement.getBoundingClientRect().width); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ArticlePreview.prototype, "personalizationParametersRequested", { | ||
get: function () { | ||
return this.domElement.getAttribute('data-cxence_widget'); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ArticlePreview.prototype, "personalizationSystemUsed", { | ||
get: function () { | ||
return this.domElement.getAttribute('data-cxense_tag'); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ArticlePreview.prototype, "title", { | ||
get: function () { | ||
// Handle lommelegen question special case | ||
if (this.domElement.querySelector('h4')) { | ||
return this.domElement.querySelector('h4').textContent.trim(); | ||
} | ||
// Handle dinside test special case | ||
if (this.domElement.querySelector('h3[itemprop="headline"]')) { | ||
return this.domElement | ||
.querySelector('h3[itemprop="headline"]') | ||
.textContent.trim(); | ||
} | ||
if (this.domElement.querySelector('.headline')) { | ||
return this.domElement.querySelector('.headline').textContent.trim(); | ||
} | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ArticlePreview.prototype, "url", { | ||
get: function () { | ||
var href = this.domElement.querySelector('a').getAttribute('href'); | ||
return get_full_url_1.default(href, this.location); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ArticlePreview; | ||
}()); | ||
exports.default = ArticlePreview; | ||
//# sourceMappingURL=article-preview.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getCookie = getCookie; | ||
exports.setCookie = setCookie; | ||
exports.expireCookie = expireCookie; | ||
/* eslint-disable no-param-reassign */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getCookie(doc, name) { | ||
var v = doc.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)"); | ||
return v ? v[2] : null; | ||
var v = doc.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)"); | ||
return v ? v[2] : null; | ||
} | ||
exports.getCookie = getCookie; | ||
function setCookie(doc, name, value, now) { | ||
expireCookie(doc, name); | ||
var date = new Date(now); | ||
date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000); | ||
var expires = date.toGMTString(); | ||
var domain = window.location.hostname; | ||
domain = domain.split(".").reverse().splice(0, 2).reverse().join("."); | ||
doc.cookie = name + "=" + value + "; Path=/; Expires=" + expires + "; Secure; Domain=" + domain; | ||
expireCookie(doc, name); | ||
var date = new Date(now); | ||
date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000); | ||
var expires = date.toUTCString(); | ||
var domain = window.location.hostname; | ||
// This sure is some funny trickery to get the right domain | ||
domain = domain | ||
.split('.') | ||
.reverse() | ||
.splice(0, 2) | ||
.reverse() | ||
.join('.'); | ||
doc.cookie = name + "=" + value + "; Path=/; Expires=" + expires + "; Secure; Domain=" + domain; | ||
} | ||
exports.setCookie = setCookie; | ||
function expireCookie(doc, name) { | ||
doc.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Secure;"; | ||
} | ||
doc.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Secure;"; | ||
} | ||
exports.expireCookie = expireCookie; | ||
//# sourceMappingURL=cookie-utils.js.map |
@@ -1,29 +0,31 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.flushCache = flushCache; | ||
exports.default = getABCookie; | ||
var _cookieUtils = require('./cookie-utils'); | ||
var abCookie = ''; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cookie_utils_1 = require("./cookie-utils"); | ||
var abCookie = null; | ||
function flushCache() { | ||
abCookie = ''; | ||
abCookie = null; | ||
} | ||
exports.flushCache = flushCache; | ||
function getABCookie(doc) { | ||
if (abCookie) { | ||
return abCookie; | ||
} | ||
if (!doc && (typeof window === 'undefined' || !window.document)) { | ||
return '101'; | ||
} | ||
abCookie = (0, _cookieUtils.getCookie)(doc || document, 'abTestCookie'); | ||
if (abCookie) { | ||
return abCookie; | ||
} | ||
return '101'; | ||
} | ||
if (abCookie || abCookie === 0) { | ||
return abCookie; | ||
} | ||
if (!doc && (typeof window === 'undefined' || !window.document)) { | ||
return 101; | ||
} | ||
var abCookieString = cookie_utils_1.getCookie(doc || document, 'abTestCookie'); | ||
if (abCookieString) { | ||
if (abCookieString.length <= 3) { | ||
var abCookieParsed = parseInt(abCookieString, 10); | ||
if (!isNaN(abCookieParsed) && | ||
abCookieParsed >= 0 && | ||
abCookieParsed < 102) { | ||
abCookie = abCookieParsed; | ||
return abCookie; | ||
} | ||
} | ||
} | ||
return 101; | ||
} | ||
exports.default = getABCookie; | ||
//# sourceMappingURL=get-ab-cookie.js.map |
@@ -1,32 +0,31 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cookie_utils_1 = require("./cookie-utils"); | ||
var plussData = null; | ||
function getPlussData(doc, nocache, cachedPlussData) { | ||
if (doc === void 0) { doc = document; } | ||
if (nocache === void 0) { nocache = false; } | ||
if (cachedPlussData === void 0) { cachedPlussData = plussData; } | ||
// Fetch id from cache if we have it | ||
if (cachedPlussData && !nocache) { | ||
return cachedPlussData; | ||
} | ||
// Fetch id from cookie if we have it | ||
var plussDataRaw = cookie_utils_1.getCookie(doc, 'xavier_pluss'); | ||
if (plussDataRaw) { | ||
var decodedPlussData = decodeURIComponent(plussDataRaw); | ||
var parsedDecodedPlussData = JSON.parse(decodedPlussData); | ||
if (parsedDecodedPlussData.access && | ||
parsedDecodedPlussData.customer_number) { | ||
plussData = { | ||
hasAccess: parsedDecodedPlussData.access, | ||
customerNumber: parsedDecodedPlussData.customer_number.toString(), | ||
}; | ||
return plussData; | ||
} | ||
} | ||
plussData = { hasAccess: false, customerNumber: null }; | ||
return plussData; | ||
} | ||
exports.default = getPlussData; | ||
var _cookieUtils = require('./cookie-utils'); | ||
var plussData = ''; | ||
function getPlussData() { | ||
var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; | ||
var nocache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var cachedPlussData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : plussData; | ||
// Fetch id from cache if we have it | ||
if (cachedPlussData && !nocache) { | ||
return cachedPlussData; | ||
} | ||
// Fetch id from cookie if we have it | ||
var plussDataRaw = (0, _cookieUtils.getCookie)(doc, 'xavier_pluss'); | ||
if (plussDataRaw) { | ||
var decodedPlussData = decodeURIComponent(plussDataRaw); | ||
var parsedDecodedPlussData = JSON.parse(decodedPlussData); | ||
if (parsedDecodedPlussData.access && parsedDecodedPlussData.customer_number) { | ||
plussData = { hasAccess: parsedDecodedPlussData.access, customerNumber: parsedDecodedPlussData.customer_number.toString() }; | ||
return plussData; | ||
} | ||
} | ||
plussData = { hasAccess: false, customerNumber: null }; | ||
return plussData; | ||
} | ||
//# sourceMappingURL=get-db-pluss-data.js.map |
@@ -1,26 +0,19 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _startsWith = require('lodash/startsWith'); | ||
var _startsWith2 = _interopRequireDefault(_startsWith); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function startsWith(fullString, searchString) { | ||
return fullString.indexOf(searchString) === 0; | ||
} | ||
function getFullUrl(href, location) { | ||
if ((0, _startsWith2.default)(href, 'http')) { | ||
return href; | ||
} | ||
if ((0, _startsWith2.default)(href, '//')) { | ||
return location.protocol + href; | ||
} | ||
if ((0, _startsWith2.default)(href, '/')) { | ||
return location.origin + href; | ||
} | ||
return '' + location.origin + location.pathname; | ||
if (startsWith(href, 'http')) { | ||
return href; | ||
} | ||
if (startsWith(href, '//')) { | ||
return location.protocol + href; | ||
} | ||
if (startsWith(href, '/')) { | ||
return location.origin + href; | ||
} | ||
return "" + location.origin + location.pathname; | ||
} | ||
exports.default = getFullUrl; | ||
exports.default = getFullUrl; | ||
//# sourceMappingURL=get-full-url.js.map |
@@ -1,7 +0,2 @@ |
'use strict'; |
Object.defineProperty(exports, "__esModule", { |
value: true |
}); |
exports.default = getHiddenStatus; |
"use strict"; |
/** |
@@ -11,31 +6,34 @@ * Figure out if the page is hidden. |
*/ |
Object.defineProperty(exports, "__esModule", { value: true }); |
function getHiddenStatus() { |
if ('hidden' in document) { |
if ('hidden' in document) { |
return { |
hidden: document.hidden, |
prefix: '', |
}; |
} |
if ('mozHidden' in document) { |
return { |
hidden: document.mozHidden, |
prefix: 'moz', |
}; |
} |
if ('oHidden' in document) { |
return { |
hidden: document.oHidden, |
prefix: 'o', |
}; |
} |
if ('webkitHidden' in document) { |
return { |
hidden: document.webkitHidden, |
prefix: 'webkit', |
}; |
} |
return { |
hidden: document.hidden, |
prefix: '' |
hidden: false, |
prefix: 'unkown', |
}; |
} |
if ('mozHidden' in document) { |
return { |
hidden: document.mozHidden, |
prefix: 'moz' |
}; |
} |
if ('oHidden' in document) { |
return { |
hidden: document.oHidden, |
prefix: 'o' |
}; |
} |
if ('webkitHidden' in document) { |
return { |
hidden: document.webkitHidden, |
prefix: 'webkit' |
}; |
} |
return { |
hidden: false, |
preview: 'unkown' |
}; |
} |
} |
exports.default = getHiddenStatus; |
//# sourceMappingURL=get-hidden-status.js.map |
@@ -1,26 +0,20 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var round_1 = __importDefault(require("./round")); | ||
function getMaxScroll(latestMaxScrollPercent, scrollTop, scrollHeight, clientHeight) { | ||
if (latestMaxScrollPercent === void 0) { latestMaxScrollPercent = null; } | ||
if (scrollTop === void 0) { scrollTop = document.documentElement.scrollTop || 0.0; } | ||
if (scrollHeight === void 0) { scrollHeight = document.documentElement.scrollHeight || 0.0; } | ||
if (clientHeight === void 0) { clientHeight = document.documentElement.clientHeight || 0.0; } | ||
var pageHeight = scrollHeight - clientHeight || 1.0; | ||
var scrollPercent = scrollTop / pageHeight; | ||
if (scrollPercent > latestMaxScrollPercent) { | ||
return round_1.default(scrollPercent, 2); | ||
} | ||
return latestMaxScrollPercent; | ||
} | ||
exports.default = getMaxScroll; | ||
var _round = require('./round'); | ||
var _round2 = _interopRequireDefault(_round); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getMaxScroll() { | ||
var latestMaxScrollPercent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var scrollTop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.documentElement.scrollTop || 0.0; | ||
var scrollHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.documentElement.scrollHeight || 0.0; | ||
var clientHeight = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : document.documentElement.clientHeight || 0.0; | ||
var pageHeight = scrollHeight - clientHeight || 1.0; | ||
var scrollPercent = scrollTop / pageHeight; | ||
if (scrollPercent > latestMaxScrollPercent) { | ||
return (0, _round2.default)(scrollPercent, 2); | ||
} | ||
return latestMaxScrollPercent; | ||
} | ||
//# sourceMappingURL=get-max-scroll-percent.js.map |
@@ -1,12 +0,10 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getReferrer() { | ||
if (typeof window === 'undefined' || !window.document) { | ||
return ''; | ||
} | ||
return document.referrer; | ||
} | ||
exports.default = getReferrer; | ||
function getReferrer() { | ||
if (typeof window === 'undefined' || !window.document) { | ||
return ''; | ||
} | ||
return document.referrer; | ||
} | ||
//# sourceMappingURL=get-referrer.js.map |
@@ -1,25 +0,31 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = getSite; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function onSite(sitePattern, hostname) { | ||
return sitePattern.test(hostname); | ||
return sitePattern.test(hostname); | ||
} | ||
function getSite(hostname) { | ||
if (!hostname && typeof window === 'undefined') { | ||
return 'unknown (no hostname)'; | ||
} | ||
var sites = [{ name: 'www.dinside.no', pattern: /.*dinside\.no$/ }, { name: 'www.dagbladet.no', pattern: /.*dagbladet\.no$/ }, { name: 'www.seher.no', pattern: /.*seher\.no$/ }, { name: 'localhost', pattern: /.*localhost$/ }, { name: 'topp.no', pattern: /.*topp\.no$/ }, { name: 'localhost', pattern: /.*ngrok\.io$/ }, { name: 'www.lommelegen.no', pattern: /.*lommelegen\.no$/ }, { name: 'www.sol.no', pattern: /.*sol\.no$/ }, { name: 'www.kk.no', pattern: /.*kk\.no$/ }, { name: 'www.vi.no', pattern: /.*vi\.no$/ }]; | ||
var foundSite = ''; | ||
sites.forEach(function (site) { | ||
if (onSite(site.pattern, hostname || window.location.hostname)) { | ||
foundSite = site.name; | ||
if (!hostname && typeof window === 'undefined') { | ||
return 'unknown (no hostname)'; | ||
} | ||
}); | ||
return foundSite || 'unknown: (' + hostname + ')'; | ||
} | ||
var sites = [ | ||
{ name: 'www.dinside.no', pattern: /.*dinside\.no$/ }, | ||
{ name: 'www.dagbladet.no', pattern: /.*dagbladet\.no$/ }, | ||
{ name: 'www.seher.no', pattern: /.*seher\.no$/ }, | ||
{ name: 'localhost', pattern: /.*localhost$/ }, | ||
{ name: 'topp.no', pattern: /.*topp\.no$/ }, | ||
{ name: 'localhost', pattern: /.*ngrok\.io$/ }, | ||
{ name: 'www.lommelegen.no', pattern: /.*lommelegen\.no$/ }, | ||
{ name: 'www.sol.no', pattern: /.*sol\.no$/ }, | ||
{ name: 'www.kk.no', pattern: /.*kk\.no$/ }, | ||
{ name: 'www.vi.no', pattern: /.*vi\.no$/ }, | ||
]; | ||
var foundSite = ''; | ||
sites.forEach(function (site) { | ||
if (onSite(site.pattern, hostname || window.location.hostname)) { | ||
foundSite = site.name; | ||
} | ||
}); | ||
return foundSite || "unknown: (" + hostname + ")"; | ||
} | ||
exports.default = getSite; | ||
//# sourceMappingURL=get-site.js.map |
@@ -1,45 +0,38 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = getXavierId; | ||
var _uuid = require('./uuid'); | ||
var _uuid2 = _interopRequireDefault(_uuid); | ||
var _cookieUtils = require('./cookie-utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var uuid_1 = __importDefault(require("./uuid")); | ||
var cookie_utils_1 = require("./cookie-utils"); | ||
var xavierId = ''; | ||
function getXavierId(docu) { | ||
var nocache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var now = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Date(); | ||
var getUUID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _uuid2.default; | ||
var cachedId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : xavierId; | ||
if (!docu && typeof document === 'undefined') { | ||
return 'xavier_no_doc'; | ||
} | ||
var doc = docu || document; | ||
// Return opt-out ID (xavier_no) for users who do not want to be tracked | ||
if ((0, _cookieUtils.getCookie)(doc || document, 'xavier_no')) { | ||
return 'xavier_no'; | ||
} | ||
// Fetch id from cache if we have it | ||
if (cachedId && !nocache) { | ||
return cachedId; | ||
} | ||
// Fetch id from cookie if we have it | ||
xavierId = (0, _cookieUtils.getCookie)(doc, 'xavier'); | ||
if (xavierId) { | ||
(0, _cookieUtils.setCookie)(doc, 'xavier', xavierId, now); | ||
function getXavierId(docu, nocache, now, getUUID, cachedId) { | ||
if (nocache === void 0) { nocache = false; } | ||
if (now === void 0) { now = new Date(); } | ||
if (getUUID === void 0) { getUUID = uuid_1.default; } | ||
if (cachedId === void 0) { cachedId = xavierId; } | ||
if (!docu && typeof document === 'undefined') { | ||
return 'xavier_no_doc'; | ||
} | ||
var doc = docu || document; | ||
// Return opt-out ID (xavier_no) for users who do not want to be tracked | ||
if (cookie_utils_1.getCookie(doc || document, 'xavier_no')) { | ||
return 'xavier_no'; | ||
} | ||
// Fetch id from cache if we have it | ||
if (cachedId && !nocache) { | ||
return cachedId; | ||
} | ||
// Fetch id from cookie if we have it | ||
xavierId = cookie_utils_1.getCookie(doc, 'xavier'); | ||
if (xavierId) { | ||
cookie_utils_1.setCookie(doc, 'xavier', xavierId, now); | ||
return xavierId; | ||
} | ||
// Generate a new id and store it | ||
xavierId = getUUID('xavierId'); | ||
cookie_utils_1.setCookie(doc, 'xavier', xavierId, now); | ||
return xavierId; | ||
} | ||
// Generate a new id and store it | ||
xavierId = getUUID('xavierId'); | ||
(0, _cookieUtils.setCookie)(doc, 'xavier', xavierId, now); | ||
return xavierId; | ||
} | ||
} | ||
exports.default = getXavierId; | ||
//# sourceMappingURL=get-xavier-id.js.map |
@@ -1,25 +0,23 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setPageView = setPageView; | ||
exports.getPageView = getPageView; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var PREFIX = 'PAGEVIEW-'; | ||
function setPageView(url, pageView) { | ||
try { | ||
window.sessionStorage.setItem(PREFIX + url, pageView); | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
try { | ||
window.sessionStorage.setItem(PREFIX + url, pageView); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.setPageView = setPageView; | ||
function getPageView(referrerUrl) { | ||
try { | ||
return window.sessionStorage.getItem(PREFIX + referrerUrl); | ||
} catch (e) { | ||
return ''; | ||
} | ||
} | ||
try { | ||
return window.sessionStorage.getItem(PREFIX + referrerUrl); | ||
} | ||
catch (e) { | ||
return ''; | ||
} | ||
} | ||
exports.getPageView = getPageView; | ||
//# sourceMappingURL=prev-pageview.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function round(value, decimals) { | ||
if (decimals === void 0) { decimals = 0; } | ||
return Number(Math.round(Number(value + "e" + decimals)) + "e-" + decimals); | ||
} | ||
exports.default = round; | ||
function round(value) { | ||
var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
return Number(Math.round(value + "e" + decimals) + "e-" + decimals); | ||
} | ||
//# sourceMappingURL=round.js.map |
@@ -1,11 +0,5 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = generateUUID; | ||
"use strict"; | ||
/* eslint-disable */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var uuidDict = {}; | ||
/** | ||
@@ -15,21 +9,22 @@ * Gives a unique but consistent id for each pageview. | ||
*/ | ||
function generateUUID() { | ||
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default'; | ||
if (key in uuidDict) { | ||
return uuidDict[key]; | ||
} | ||
// Public Domain/MIT | ||
var d = new Date().getTime(); | ||
if (typeof performance !== 'undefined' && typeof performance.now === 'function') { | ||
d += performance.now(); // use high-precision timer if available | ||
} | ||
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
var r = (d + Math.random() * 16) % 16 | 0; | ||
d = Math.floor(d / 16); | ||
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16); | ||
}); | ||
uuidDict[key] = uuid; | ||
return uuid; | ||
} | ||
function generateUUID(key) { | ||
if (key === void 0) { key = 'default'; } | ||
if (key in uuidDict) { | ||
return uuidDict[key]; | ||
} | ||
// Public Domain/MIT | ||
var d = new Date().getTime(); | ||
if (typeof performance !== 'undefined' && | ||
typeof performance.now === 'function') { | ||
d += performance.now(); // use high-precision timer if available | ||
} | ||
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
var r = (d + Math.random() * 16) % 16 | 0; | ||
d = Math.floor(d / 16); | ||
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16); | ||
}); | ||
uuidDict[key] = uuid; | ||
return uuid; | ||
} | ||
exports.default = generateUUID; | ||
//# sourceMappingURL=uuid.js.map |
{ | ||
"name": "@aller/blink-labrador", | ||
"version": "0.6.4", | ||
"version": "0.6.8", | ||
"description": "Library for using blink on Labrador", | ||
"main": "lib/main.js", | ||
"types": "lib/main.d.ts", | ||
"typings": "lib/main.d.ts", | ||
"files": [ | ||
@@ -13,11 +15,11 @@ "package.json", | ||
{ | ||
"path": "src/main.js" | ||
"path": "lib/main.js" | ||
} | ||
], | ||
"scripts": { | ||
"size": "size-limit", | ||
"size": "npm run build && size-limit", | ||
"test": "jest src/** --env=jsdom", | ||
"lint": "eslint src/**", | ||
"transpile": "babel src/ -d lib/ --ignore=**/*.test.js", | ||
"prepare": "npm run transpile", | ||
"lint": "tslint --project tsconfig.json {src,test}/**/*.ts", | ||
"build": "rm -rf lib && tsc -d", | ||
"prepare": "npm run build", | ||
"bundle": "rollup -c" | ||
@@ -35,4 +37,20 @@ }, | ||
"jest": { | ||
"testEnvironment": "jsdom", | ||
"verbose": true, | ||
"testURL": "http://localhost" | ||
"testURL": "http://localhost", | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
] | ||
}, | ||
@@ -54,6 +72,8 @@ "prettier": { | ||
"dependencies": { | ||
"@aller/blink": "2.3.0", | ||
"@aller/blink": "^3.1.3", | ||
"@soldotno/aller-in-view": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^23.3.2", | ||
"@types/lodash": "^4.14.116", | ||
"babel-cli": "^6.26.0", | ||
@@ -74,3 +94,6 @@ "babel-plugin-external-helpers": "^6.22.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"size-limit": "^0.19.0" | ||
"rollup-plugin-typescript": "^1.0.0", | ||
"size-limit": "^0.19.0", | ||
"ts-jest": "^23.10.1", | ||
"typescript": "^3.0.3" | ||
}, | ||
@@ -77,0 +100,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
231434
134
2934
21
18
1
+ Added@aller/blink@3.3.1(transitive)
- Removed@aller/blink@2.3.0(transitive)
Updated@aller/blink@^3.1.3