Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getOriginalSource(opts = {}) {
const config = Object.assign({}, CONFIG, opts)
const { referrer, originalSourceKey } = config
// 1. try first source browser storage
const originalSrc = storage.getItem(originalSourceKey, { storage: config.storage })
if (originalSrc) {
return parsePipeString(originalSrc)
}
// 2. then try __utmz cookie
const utmzCookie = getCookie('__utmz')
if (utmzCookie) {
const parsedCookie = parsePipeString(utmzCookie)
if (parsedCookie) {
setOriginalSource(parsedCookie, config)
return parsedCookie
}
}
// 3. Then try referrer url and utm params
const ref = (inBrowser) ? (referrer || document.referrer) : ''
const refData = parseReferrer(ref)
setOriginalSource(refData, config)
export function getOriginalLandingPage(opts = {}) {
const config = Object.assign({}, CONFIG, opts)
const key = config.originalLandingPageKey
const storageConfig = { storage: config.storage }
// 1. try first source browser storage
const originalLandingPage = storage.getItem(key, storageConfig)
if (originalLandingPage) {
return originalLandingPage
}
const url = (inBrowser) ? window.location.href : ''
storage.setItem(key, url, storageConfig)
return url
}
export function getOriginalLandingPage(opts = {}) {
const config = Object.assign({}, CONFIG, opts)
const key = config.originalLandingPageKey
const storageConfig = { storage: config.storage }
// 1. try first source browser storage
const originalLandingPage = storage.getItem(key, storageConfig)
if (originalLandingPage) {
return originalLandingPage
}
const url = (inBrowser) ? window.location.href : ''
storage.setItem(key, url, storageConfig)
return url
}
return store => next => action => {
const { type, key, value, options } = action
if (type === EVENTS.setItem || type === EVENTS.removeItem) {
if (action.abort) {
return next(action)
}
// Run storage set or remove
if (type === EVENTS.setItem) {
storage.setItem(key, value, options)
} else {
storage.removeItem(key, options)
}
}
return next(action)
}
}
return store => next => action => {
const { type, userId, traits, options, callback } = action
if (type === EVENTS.IDENTIFY_INIT) {
const identifyCalls = getIntegrationsWithMethod(getIntegrations(), 'identify')
const cb = getCallbackFromArgs(traits, options, callback)
// TODO add aborting
// if (action.abort) {
//
// }
storage.setItem(USER_ID, userId)
if (traits) {
storage.setItem(USER_TRAITS, traits)
}
// No identify middleware attached
if (!identifyCalls.length) {
store.dispatch({
type: EVENTS.IDENTIFY,
userId: userId,
traits: traits,
options: options,
// callback: callback
})
return store.dispatch({
...{ type: EVENTS.IDENTIFY_COMPLETE }
})
return store => next => action => {
const { type, userId, traits, options, callback } = action
if (type === EVENTS.IDENTIFY_INIT) {
const identifyCalls = getIntegrationsWithMethod(getIntegrations(), 'identify')
const cb = getCallbackFromArgs(traits, options, callback)
// TODO add aborting
// if (action.abort) {
//
// }
storage.setItem(USER_ID, userId)
if (traits) {
storage.setItem(USER_TRAITS, traits)
}
// No identify middleware attached
if (!identifyCalls.length) {
store.dispatch({
type: EVENTS.IDENTIFY,
userId: userId,
traits: traits,
options: options,
// callback: callback
})
return store.dispatch({
...{ type: EVENTS.IDENTIFY_COMPLETE }
})
}
// TODO SAVE ID TO LOCALSTORAGE
const nonAbortable = () => {
// throw new Error(`${errorUrl}3`)
throw new Error('Abort disabled in listener')
}
// Async promise resolver
const resolvePromise = (resolver, cb) => {
return (payload) => {
if (cb) cb(payload)
resolver(payload)
}
}
// Parse URL parameters
const params = paramsParse()
// Initialize visitor information
const initialUser = getPersistedUserData(params)
/**
* Analytic instance returned from initialization
* @typedef {Object} AnalyticsInstance
* @property {Identify} identify - Identify a user
* @property {Track} track - Track an analytics event
* @property {Page} page - Trigger page view
* @property {User} user - Get user data
* @property {Reset} reset - Clear information about user & reset analytics
* @property {Ready} ready - Fire callback on analytics ready event
* @property {On} on - Fire callback on analytics lifecycle events.
* @property {Once} once - Fire callback on analytics lifecycle events once.
* @property {GetState} getState - Get data about user, activity, or context.
* @property {Storage} storage - storage methods
let referrer
let locale
let timeZone
if (process.browser) {
osName = getOSNameBrowser()
referrer = document.referrer
locale = getBrowserLocale()
timeZone = getTimeZone()
} else {
osName = getOSNameNode()
referrer = {}
}
const initialState = {
initialized: false,
sessionId: uuid(),
app: null,
version: null,
debug: false,
offline: (inBrowser) ? !navigator.onLine : false, // use node network is-online
os: {
name: osName,
},
userAgent: (inBrowser) ? navigator.userAgent : 'node', // https://github.com/bestiejs/platform.js
library: {
name: 'analytics',
// TODO fix version number. npm run publish:patch has wrong version
version: process.env.VERSION
},
timezone: timeZone,
locale: locale,
campaign: {},
export function getOriginalSource(opts = {}) {
const config = Object.assign({}, CONFIG, opts)
const { referrer, originalSourceKey } = config
// 1. try first source browser storage
const originalSrc = storage.getItem(originalSourceKey, { storage: config.storage })
if (originalSrc) {
return parsePipeString(originalSrc)
}
// 2. then try __utmz cookie
const utmzCookie = getCookie('__utmz')
if (utmzCookie) {
const parsedCookie = parsePipeString(utmzCookie)
if (parsedCookie) {
setOriginalSource(parsedCookie, config)
return parsedCookie
}
}
// 3. Then try referrer url and utm params
const ref = (inBrowser) ? (referrer || document.referrer) : ''
const refData = parseReferrer(ref)
setOriginalSource(refData, config)
return refData
}
const originalSrc = storage.getItem(originalSourceKey, { storage: config.storage })
if (originalSrc) {
return parsePipeString(originalSrc)
}
// 2. then try __utmz cookie
const utmzCookie = getCookie('__utmz')
if (utmzCookie) {
const parsedCookie = parsePipeString(utmzCookie)
if (parsedCookie) {
setOriginalSource(parsedCookie, config)
return parsedCookie
}
}
// 3. Then try referrer url and utm params
const ref = (inBrowser) ? (referrer || document.referrer) : ''
const refData = parseReferrer(ref)
setOriginalSource(refData, config)
return refData
}