UNPKG

owtlab-tracking

Version:
107 lines (96 loc) 3.11 kB
import OwtlabCore from './index'; import each from './core/utils/each'; import extend from './core/utils/extend'; import { listenerCore } from './utils/listener'; import { recordEvent, recordEvents } from './record-events-browser'; import { deferEvent, deferEvents, queueCapacity, queueInterval, recordDeferredEvents } from './defer-events'; import { extendEvent, extendEvents } from './extend-events'; import { initAutoTrackingCore } from './browser-auto-tracking'; import { getBrowserProfile } from './helpers/getBrowserProfile'; import { getDatetimeIndex } from './helpers/getDatetimeIndex'; import { getDomainName } from './helpers/getDomainName'; import { getDomNodePath } from './helpers/getDomNodePath'; import { getDomNodeProfile } from './helpers/getDomNodeProfile'; import { getScreenProfile } from './helpers/getScreenProfile'; import { getScrollState } from './helpers/getScrollState'; import { getUniqueId } from './helpers/getUniqueId'; import { getWindowProfile } from './helpers/getWindowProfile'; import { cookie } from './utils/cookie'; import { deepExtend } from './utils/deepExtend'; import { serializeForm } from './utils/serializeForm'; import { timer } from './utils/timer'; import { setOptOut } from './utils/optOut'; import { isLocalStorageAvailable } from './utils/localStorage'; // ------------------------ // Methods // ------------------------ extend(OwtlabCore.prototype, { recordEvent, recordEvents, }); extend(OwtlabCore.prototype, { deferEvent, deferEvents, queueCapacity, queueInterval, recordDeferredEvents, setOptOut, }); extend(OwtlabCore.prototype, { extendEvent, extendEvents, }); // ------------------------ // Auto-Tracking // ------------------------ const initAutoTracking = initAutoTrackingCore(OwtlabCore); extend(OwtlabCore.prototype, { initAutoTracking, }); // ------------------------ // Helpers // ------------------------ extend(OwtlabCore.helpers, { getBrowserProfile, getDatetimeIndex, getDomainName, getDomNodePath, getDomNodeProfile, getScreenProfile, getScrollState, getUniqueId, getWindowProfile, }); // ------------------------ // Utils // ------------------------ const listener = listenerCore(OwtlabCore); extend(OwtlabCore.utils, { cookie, deepExtend, listener, serializeForm, timer, }); OwtlabCore.listenTo = (listenerHash) => { each(listenerHash, (callback, key) => { const split = key.split(' '); const eventType = split[0]; const selector = split.slice(1, split.length).join(' '); // Create an unassigned listener return listener(selector).on(eventType, callback); }); }; export let owtlabGlobals; if (typeof webpackOwtlabGlobals !== 'undefined') { owtlabGlobals = webpackOwtlabGlobals; } if (isLocalStorageAvailable && localStorage.getItem('optout')) { OwtlabCore.optedOut = true; } if (navigator.doNotTrack === '1' || navigator.doNotTrack === 'yes') { OwtlabCore.doNotTrack = true; } export const Owtlab = OwtlabCore.extendLibrary(OwtlabCore); // deprecated, left for backward compatibility export const OwtlabTracking = Owtlab; export default Owtlab;