-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Simmons
authored and
John Simmons
committed
May 10, 2020
1 parent
9360783
commit 3f823b6
Showing
7 changed files
with
10,559 additions
and
263 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,203 @@ | ||
/** | ||
* Lytics | ||
* https://learn.lytics.com/documentation/product/features/lytics-javascript-tag/using-version-2/installation-configuration | ||
* https://learn.lytics.com/documentation/product/features/lytics-javascript-tag/using-version-3/installation-configuration | ||
* https://learn.lytics.com/documentation/product/features/lytics-javascript-tag/using-version-2/collecting-data | ||
* https://learn.lytics.com/documentation/product/features/lytics-javascript-tag/using-version-3/collecting-data | ||
* | ||
* @class | ||
* @extends BaseProvider | ||
*/ | ||
|
||
class LyticsProvider extends BaseProvider { | ||
constructor() { | ||
super(); | ||
this._key = "LYTICS"; | ||
this._pattern = /c\.lytics.io\/c\//; | ||
this._name = "Lytics"; | ||
this._type = "marketing"; | ||
} | ||
|
||
/** | ||
* Retrieve the column mappings for default columns (account, event type) | ||
* | ||
* @return {{}} | ||
*/ | ||
get columnMapping() | ||
{ | ||
return { | ||
"account": "cid", | ||
"requestType": "requestTypeParsed" | ||
}; | ||
} | ||
|
||
/** | ||
* Retrieve the group names & order | ||
* | ||
* @returns {*[]} | ||
*/ | ||
get groups() | ||
{ | ||
return [ | ||
{ | ||
"key": "general", | ||
"name": "General" | ||
}, | ||
{ | ||
"key": "configuration", | ||
"name": "Configuration" | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Get all of the available URL parameter keys | ||
* | ||
* @returns {{}} | ||
*/ | ||
get keys() | ||
{ | ||
return { | ||
"loadid" : { | ||
"name": "loadid", | ||
"group": "configuration" | ||
}, | ||
"blockload" : { | ||
"name": "blockload", | ||
"group": "configuration" | ||
}, | ||
"stream" : { | ||
"name": "stream", | ||
"group": "configuration" | ||
}, | ||
"sessecs" : { | ||
"name": "sessecs", | ||
"group": "configuration" | ||
}, | ||
"qsargs" : { | ||
"name": "qsargs", | ||
"group": "configuration" | ||
}, | ||
"_e" : { | ||
"name": "Event (_e)", | ||
"group": "general" | ||
}, | ||
"_ref" : { | ||
"name": "Referral Domain (_ref)", | ||
"group": "general" | ||
}, | ||
"_tz" : { | ||
"name": "User Time Zone (_tz)", | ||
"group": "general" | ||
}, | ||
"_ul" : { | ||
"name": "User Language (_ul)", | ||
"group": "general" | ||
}, | ||
"_sz" : { | ||
"name": "Display Size (_sz)", | ||
"group": "general" | ||
}, | ||
"_ts" : { | ||
"name": "Timestamp (_ts)", | ||
"group": "general" | ||
}, | ||
"_nmob" : { | ||
"name": "Not Mobile Device (_nmob)", | ||
"group": "general" | ||
}, | ||
"_device" : { | ||
"name": "Current Device (_device)", | ||
"group": "general" | ||
}, | ||
"url" : { | ||
"name": "URL (url)", | ||
"group": "general" | ||
}, | ||
"_uid" : { | ||
"name": "Lytics UID (_uid)", | ||
"group": "general" | ||
}, | ||
"_uido" : { | ||
"name": "Lytics UID (_uido)", | ||
"group": "general" | ||
}, | ||
"_v" : { | ||
"name": "Javascript Tag Version (_v)", | ||
"group": "general" | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Parse a given URL parameter into human-readable form | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
* | ||
* @returns {void|{}} | ||
LEFT IN AS EXAMPLE | ||
handleQueryParam(name, value) | ||
{ | ||
let result = {}; | ||
if(name.indexOf("attrs.") === 0) { | ||
result = { | ||
"key": name, | ||
"field": name.replace("attrs.", ""), | ||
"value": value, | ||
"group": "customattributes" | ||
}; | ||
} | ||
else { | ||
result = super.handleQueryParam(name, value); | ||
} | ||
return result; | ||
}*/ | ||
|
||
/** | ||
* Parse custom properties for a given URL | ||
* | ||
* @param {string} url | ||
* @param {object} params | ||
* | ||
* @returns {void|Array} | ||
*/ | ||
handleCustom(url, params) | ||
{ | ||
let results = []; | ||
|
||
// Client Code | ||
const clientCodeRe = /\/c\/(.+)$/; | ||
let clientCodematches = url.pathname.match(clientCodeRe); | ||
if(clientCodematches !== null) { | ||
console.log(clientCodematches[1]); | ||
results.push({ | ||
"key": "cid", | ||
"field": "Account ID (cid)", | ||
"value": clientCodematches[1], | ||
"group": "general" | ||
}); | ||
} | ||
|
||
|
||
// Event Type (_e) or (event) value parsed to requesttype | ||
let eventType = params.get("_e") || params.get("event") || "Other"; | ||
const eventDict = { | ||
"pv" : "Page View", | ||
"conversion": "Conversion" | ||
}; | ||
let eventTypeValue = eventDict[eventType] ? eventDict[eventType] : eventType; | ||
results.push({ | ||
"key": "requestTypeParsed", | ||
"field": "Request Type", | ||
"value": eventTypeValue, | ||
"group": "general" | ||
}); | ||
|
||
|
||
return results; | ||
} // handle custom | ||
} // class |
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,115 @@ | ||
import test from 'ava'; | ||
|
||
import { default as LyticsProvider } from "../source/providers/Lytics"; | ||
import { OmnibugProvider } from "../source/providers.js"; | ||
|
||
const PIXEL_ID = "LYTICS"; | ||
|
||
test("LyticsProvider returns provider information", (t) => { | ||
let provider = new LyticsProvider(); | ||
t.is(provider.key, PIXEL_ID, "Key should always be Lytics"); | ||
t.is(provider.type, "Marketing", "Type should always be marketing"); | ||
t.true(typeof provider.name === "string" && provider.name !== "", "Name should exist"); | ||
t.true(typeof provider.pattern === 'object' && provider.pattern instanceof RegExp, "Pattern should be a RegExp value"); | ||
}); | ||
|
||
test("LyticsProvider pattern should match Lytics calls", t => { | ||
let provider = new LyticsProvider(), | ||
urls = [ | ||
"https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?pf-widget-id=gdpr-consent&pf-widget-type=message&pf-widget-layout=slideout&pf-widget-variant=1&pf-widget-event=show&_ts=1589047241346&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_e=pv&_sesstart=1&_tz=-4&_ul=en-US&_sz=1920x1200&_ca=jstag1", | ||
"https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?userid=1234&facebook_id=abc123&twitter_id=def123&linkedin_id=hij123&email=jon%40castleblack.com&name=Jon%20Snow&first_name=Jon&last_name=Snow&title=King%20in%20the%20North&company=House%20Stark&phone=555-555-5555&cell=555-555-5555&age=21&gender=m&city=Winterfell&state=Westeros&country=IE&zip=55555&origin=organic&status=known&_ts=1589047725127&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
"https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?_e=pv&_tz=-4&_ul=en-US&_sz=1920x1200&_ts=1589047923087&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
"https://c.lytics.io/c/07fff5da924b3993e5b668467ac1d2d5?OnetrustActiveGroups=%2C0_37820%2C1%2C0_37809%2C2%2C0_37810%2C3%2C0_37811%2C4%2C0_37812%2C0_37813%2C0_37814%2C0_37815%2C0_37818%2C0_37819%2C0_37822%2C0_37823%2C0_37821%2C0_37816%2C0_37817%2C0_87228%2C0_87229%2C0_87227%2C&_ts=1589048050835&_nmob=t&_device=desktop&url=www.regit.cars%2F&_v=3.0.3&_uid=u_670591093815502600&_getid=t" | ||
], | ||
badUrls = [ | ||
"https://snap.licdn.com/li.lms-analytics/insight.min.js", | ||
"https://omnibug.io/testing" | ||
]; | ||
|
||
urls.forEach((url) => { | ||
t.true(provider.checkUrl(url)); | ||
}); | ||
|
||
badUrls.forEach((url) => { | ||
t.false(provider.checkUrl(url), "Provider should not match on non-provider based URLs"); | ||
}); | ||
}); | ||
|
||
test("OmnibugProvider returns Lytics", t => { | ||
let url = "https://c.lytics.io/c/5a4ace928f7786173d963ced2784797f?ga_cid=1117987689.1589047241&_ts=1589047242522&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
results = OmnibugProvider.parseUrl(url); | ||
t.true(typeof results === "object" && results !== null, "Results is a non-null object"); | ||
t.is(results.provider.key, PIXEL_ID, "Results provider is Lytics"); | ||
}); | ||
|
||
test("LyticsProvider returns client ID", t => { | ||
let provider = new LyticsProvider(), | ||
url = "https://c.lytics.io/c/5a4ace928f7786173d963ced2784797f?ga_cid=1117987689.1589047241&_ts=1589047242522&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
results = provider.parseUrl(url), | ||
cid = results.data.find((result) => { | ||
return result.key === "cid"; | ||
}); | ||
|
||
t.is(typeof cid, "object"); | ||
t.is(cid.field, "Account ID (cid)"); | ||
t.is(cid.value, "5a4ace928f7786173d963ced2784797f"); | ||
|
||
}); | ||
|
||
test("LyticsProvider returns data", t => { | ||
let provider = new LyticsProvider(), | ||
url = "https://c.lytics.io/c/5a4ace928f7786173d963ced2784797f?ga_cid=1117987689.1589047241&_ts=1589047242522&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
results = provider.parseUrl(url), | ||
ts = results.data.find((result) => { | ||
return result.key === "_ts"; | ||
}); | ||
|
||
t.is(typeof ts, "object"); | ||
t.is(ts.field, "Timestamp (_ts)"); | ||
t.is(ts.value, "1589047242522"); | ||
|
||
}); | ||
|
||
test("LyticsProvider returns custom events", t => { | ||
let provider = new LyticsProvider(), | ||
pvUrl = "https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?_e=pv&_tz=-4&_ul=en-US&_sz=1920x1200&_ts=1589047923087&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
pvResults = provider.parseUrl(pvUrl), | ||
customPvEvent = pvResults.data.find((result) => { | ||
return result.key === "requestTypeParsed"; | ||
}), | ||
convUrl = "https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?event=conversion&campaign_id=someconversionid&variation_id=somevariationid¤cy=USD&value=25.99&_ts=1589147594430&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
convResults = provider.parseUrl(convUrl), | ||
customConvEvent = convResults.data.find((result) => { | ||
return result.key === "requestTypeParsed"; | ||
}), | ||
otherEventUrl = "https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?event=someEvent&campaign_id=someconversionid&variation_id=somevariationid¤cy=USD&value=25.99&_ts=1589147594430&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
otherEventResults = provider.parseUrl(otherEventUrl), | ||
customOtherEvent = otherEventResults.data.find((result) => { | ||
return result.key === "requestTypeParsed"; | ||
}), | ||
noEventUrl = "https://c.lytics.io/c/00ed91c03664aaf1ea539a87d4c560e7?campaign_id=someconversionid&variation_id=somevariationid¤cy=USD&value=25.99&_ts=1589147594430&_nmob=t&_device=desktop&url=www.lytics.com%2F&_uid=91684.5253390131&_v=2.0.0&_ca=jstag1", | ||
noEventResults = provider.parseUrl(noEventUrl), | ||
customNoEvent = noEventResults.data.find((result) => { | ||
return result.key === "requestTypeParsed"; | ||
}); | ||
|
||
|
||
t.is(typeof customPvEvent, "object"); | ||
t.is(customPvEvent.field, "Request Type"); | ||
t.is(customPvEvent.value, "Page View"); | ||
|
||
t.is(typeof customConvEvent, "object"); | ||
t.is(customConvEvent.field, "Request Type"); | ||
t.is(customConvEvent.value, "Conversion"); | ||
|
||
t.is(typeof customOtherEvent, "object"); | ||
t.is(customOtherEvent.field, "Request Type"); | ||
t.is(customOtherEvent.value, "someEvent"); | ||
|
||
t.is(typeof customNoEvent, "object"); | ||
t.is(customNoEvent.field, "Request Type"); | ||
t.is(customNoEvent.value, "Other"); | ||
|
||
|
||
|
||
}); |
Oops, something went wrong.