UNPKG

oa-frontend-conversiontracking

Version:

Stores click-id passed in URL to landingpage; submits click-id to network on conversion

173 lines (149 loc) 5.5 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ /*! * domready (c) Dustin Diaz 2014 - License MIT */ !function (name, definition) { if (typeof module != 'undefined') module.exports = definition() else if (typeof define == 'function' && typeof define.amd == 'object') define(definition) else this[name] = definition() }('domready', function () { var fns = [], listener , doc = document , hack = doc.documentElement.doScroll , domContentLoaded = 'DOMContentLoaded' , loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState) if (!loaded) doc.addEventListener(domContentLoaded, listener = function () { doc.removeEventListener(domContentLoaded, listener) loaded = 1 while (listener = fns.shift()) listener() }) return function (fn) { loaded ? setTimeout(fn, 0) : fns.push(fn) } }); },{}],2:[function(require,module,exports){ /* * Based on https://stackoverflow.com/a/23838252/448426 * Modified to use both localStorage and cookies redundantly instead as fallback and to store cookies on root domain */ module.exports = (function BrowserStorage() { /** * Whether the current browser supports local storage as a way of storing data * @var {Boolean} */ var _hasLocalStorageSupport = (function () { try { return 'localStorage' in window && window['localStorage'] !== null; } catch (e) { return false; } })(); /** * @param {String} name The name of the property to read from this document's cookies * @return {?String} The specified cookie property's value (or null if it has not been set) */ var _readCookie = function (name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; }; /** * @param {String} name The name of the property to set by writing to a cookie * @param {String} value The value to use when setting the specified property * @param {Number} [days] The number of days until the storage of this item expires */ var _writeCookie = function (name, value, days) { var expiration = (function () { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); return "; expires=" + date.toUTCString(); } else { return ""; } })(); var domain = (function () { var i = 0, domain = document.domain, p = domain.split('.'), s = '_gd' + (new Date()).getTime(); while (i < (p.length - 1) && document.cookie.indexOf(s + '=' + s) == -1) { domain = p.slice(-1 - (++i)).join('.'); document.cookie = s + "=" + s + ";domain=" + domain + ";"; } document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; })(); document.cookie = name + "=" + value + expiration + "; path=/;domain=" + domain; }; return { /** * @param {String} name The name of the property to set * @param {String} value The value to use when setting the specified property * @param {Number} [days] The number of days until the cookie of this item expires */ set: function (name, value, days) { if (_hasLocalStorageSupport) { localStorage.setItem(name, value); } _writeCookie(name, value, days); }, /** * @param {String} name The name of the value to retrieve * @return {?String} The value of the */ get: function (name) { if (_hasLocalStorageSupport && localStorage.getItem(name)) { return localStorage.getItem(name); } return _readCookie(name); }, /** * @param {String} name The name of the value to delete/remove from storage */ remove: function (name) { if (_hasLocalStorageSupport) { localStorage.removeItem(name) } this.set(name, "", -1); } }; }); },{}],3:[function(require,module,exports){ (function () { var domready = require("domready"); var cs = document.currentScript || (function () { var scripts = document.querySelectorAll('[data-name="oalanding"]'); if (scripts[0]) { return scripts[0]; } scripts = document.querySelectorAll('[data-advertiser]'); return scripts[0]; })(); domready(function () { var BrowserStorage = require('./browserstorage')(); if (cs) { var param = cs.getAttribute('data-param') || cs.getAttribute('data-params') || 'oa_id,oa_clickid'; var params = param.split(','); var cookie_days = cs.getAttribute('data-cookie-days') || '30'; var click_id = ''; for (var i = 0; i < params.length; i++) { var x = params[i].replace(/^\s+|\s+$/gm, ''); if (x.length) { click_id = decodeURIComponent((new RegExp('[?|&]' + x + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null; if (click_id) { break; } } } if (click_id) { BrowserStorage.set('oa-click-id', click_id, cookie_days); } } }); }).call(this); },{"./browserstorage":2,"domready":1}]},{},[3]);