-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from driveback/develop
Develop
- Loading branch information
Showing
24 changed files
with
4,351 additions
and
189 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "digital-data-manager", | ||
"description": "The hassle-free way to integrate Digital Data Layer on your website.", | ||
"author": "Driveback LLC <[email protected]>", | ||
"version": "1.0.0-beta6", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"main": "dist/dd-manager.js", | ||
"directories": { | ||
|
@@ -51,6 +51,7 @@ | |
"eslint-plugin-react": "^3.10.0", | ||
"exorcist": "^0.4.0", | ||
"faucet": "0.0.1", | ||
"js-cookie": "^2.1.0", | ||
"karma": "^0.13.15", | ||
"karma-babel-preprocessor": "^6.0.1", | ||
"karma-browserify": "^4.4.0", | ||
|
@@ -60,7 +61,7 @@ | |
"karma-safari-launcher": "^0.1.1", | ||
"karma-sauce-launcher": "^0.3.0", | ||
"karma-tap": "^1.0.3", | ||
"mocha": "2.3.4", | ||
"mocha": "^2.4.4", | ||
"polyify": "0.0.4", | ||
"sinon": "^1.17.2", | ||
"tape": "^4.2.2", | ||
|
@@ -70,6 +71,8 @@ | |
"dependencies": { | ||
"async": "^1.5.0", | ||
"component-clone": "^0.2.2", | ||
"debug": "^2.2.0" | ||
"debug": "^2.2.0", | ||
"store": "^1.3.20", | ||
"uuid": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import htmlGlobals from './functions/htmlGlobals.js'; | ||
import uuid from 'uuid'; | ||
|
||
class DigitalDataEnricher | ||
{ | ||
constructor(digitalData, storage, options) { | ||
this.digitalData = digitalData; | ||
this.storage = storage; | ||
this.options = Object.assign({ | ||
sessionLength: 3600, | ||
}, options); | ||
} | ||
|
||
setDigitalData(digitalData) { | ||
this.digitalData = digitalData; | ||
} | ||
|
||
setStorage(storage) { | ||
this.storage = storage; | ||
} | ||
|
||
getStorage() { | ||
return this.storage; | ||
} | ||
|
||
enrichDigitalData() { | ||
this.enrichPageData(); | ||
this.enrichUserData(); | ||
this.enrichContextData(); | ||
} | ||
|
||
enrichPageData() { | ||
const page = this.digitalData.page; | ||
|
||
page.path = page.path || this.getHtmlGlobals().getLocation().pathname; | ||
page.referrer = page.referrer || this.getHtmlGlobals().getDocument().referrer; | ||
page.queryString = page.queryString || this.getHtmlGlobals().getLocation().search; | ||
page.title = page.title || this.getHtmlGlobals().getDocument().title; | ||
page.url = page.url || this.getHtmlGlobals().getLocation().href; | ||
page.hash = page.hash || this.getHtmlGlobals().getLocation().hash; | ||
} | ||
|
||
enrichUserData() { | ||
const user = this.digitalData.user; | ||
user.anonymousId = this.getUserAnonymousId(); | ||
} | ||
|
||
enrichContextData() { | ||
const context = this.digitalData.context; | ||
context.userAgent = this.getHtmlGlobals().getNavigator().userAgent; | ||
} | ||
|
||
/** | ||
* Can be overriden for test purposes | ||
* @returns {{getDocument, getLocation, getNavigator}} | ||
*/ | ||
getHtmlGlobals() { | ||
return htmlGlobals; | ||
} | ||
|
||
getUserAnonymousId() { | ||
let anonymousId = this.storage.get('user.anonymousId'); | ||
if (!anonymousId) { | ||
anonymousId = uuid(); | ||
this.storage.set('user.anonymousId', anonymousId); | ||
} | ||
return anonymousId; | ||
} | ||
|
||
getOption(name) { | ||
return this.options[name]; | ||
} | ||
} | ||
|
||
export default DigitalDataEnricher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import store from 'store'; | ||
import cookie from 'js-cookie'; | ||
import debug from 'debug'; | ||
import topDomain from './functions/topDomain.js'; | ||
|
||
class Storage | ||
{ | ||
constructor(options) { | ||
this.options = Object.assign({ | ||
cookieDomain: topDomain(location.href), | ||
cookieMaxAge: 31536000000, // default to a year | ||
prefix: 'ddl:', | ||
}, options); | ||
|
||
// http://curl.haxx.se/rfc/cookie_spec.html | ||
// https://publicsuffix.org/list/effective_tld_names.dat | ||
// | ||
// try setting a dummy cookie with the options | ||
// if the cookie isn't set, it probably means | ||
// that the domain is on the public suffix list | ||
// like myapp.herokuapp.com or localhost / ip. | ||
if (this.getOption('cookieDomain')) { | ||
cookie.set('__tld__', true, { | ||
domain: this.getOption('cookieDomain'), | ||
}); | ||
if (!this.get('__tld__')) { | ||
debug('fallback to domain=null'); | ||
this.setOption('cookieDomain', null); | ||
} | ||
cookie.remove('__tld__'); | ||
} | ||
} | ||
|
||
set(key, val, exp) { | ||
key = this.prefix + key; | ||
if (store.enabled) { | ||
store.set(key, { | ||
val: val, | ||
exp: exp, | ||
time: new Date().getTime(), | ||
}); | ||
} else { | ||
exp = exp || this.getOption('cookieMaxAge'); | ||
const expDays = exp / 86400; | ||
cookie.set(key, val, { | ||
expires: expDays, | ||
domain: this.getOption('cookieDomain'), | ||
}); | ||
} | ||
} | ||
|
||
get(key) { | ||
key = this.prefix + key; | ||
if (store.enabled) { | ||
const info = store.get(key); | ||
if (!info) { | ||
return null; | ||
} | ||
if (new Date().getTime() - info.time > info.exp) { | ||
return null; | ||
} | ||
return info.val; | ||
} | ||
return cookie.get(key); | ||
} | ||
|
||
remove(key) { | ||
key = this.prefix + key; | ||
if (store.enabled) { | ||
return store.remove(key); | ||
} | ||
cookie.remove(key); | ||
} | ||
|
||
clear() { | ||
if (store.enabled) { | ||
return store.clear(); | ||
} | ||
} | ||
|
||
isEnabled() { | ||
return store.enabled; | ||
} | ||
|
||
getOption(name) { | ||
return this.options[name]; | ||
} | ||
} | ||
|
||
export default Storage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.