Skip to content

Commit

Permalink
add lytics provider
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simmons authored and John Simmons committed May 10, 2020
1 parent 9360783 commit 3f823b6
Show file tree
Hide file tree
Showing 7 changed files with 10,559 additions and 263 deletions.
9,773 changes: 9,773 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"url": "https://github.com/MisterPhilip/omnibug/issues"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
Expand All @@ -99,20 +99,20 @@
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/preset-env": "^7.6.3",
"@babel/preset-env": "^7.9.6",
"@babel/preset-stage-2": "^7.0.0",
"@babel/register": "^7.6.2",
"@fortawesome/fontawesome-free": "^5.12.1",
"@babel/register": "^7.9.0",
"@fortawesome/fontawesome-free": "^5.13.0",
"@ungap/url-search-params": "^0.1.0",
"ava": "^1.4.1",
"babel-plugin-istanbul": "^6.0.0",
"browser-env": "^3.2.6",
"coveralls": "^3.0.9",
"cross-env": "^7.0.0",
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-prettier": "^6.11.0",
"esm": "^3.2.25",
"grunt": "^1.0.4",
"grunt": "^1.1.0",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-compress": "^1.6.0",
"grunt-contrib-concat": "^1.0.1",
Expand All @@ -121,15 +121,15 @@
"grunt-eslint": "^22.0.0",
"grunt-sass": "^3.1.0",
"grunt-text-replace": "^0.4.0",
"node-sass": "^4.13.0",
"nyc": "^15.0.0",
"sinon": "^9.0.0",
"node-sass": "^4.14.1",
"nyc": "^15.0.1",
"sinon": "^9.0.2",
"sinon-chrome": "^3.0.0"
},
"homepage": "https://omnibug.io/",
"dependencies": {
"spectre.css": "^0.5.8",
"yarn": "^1.22.0"
"yarn": "^1.22.4"
},
"engines": {
"node": ">=12.16.0",
Expand Down
Binary file added src/assets/images/icons/LYTICS16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/styles/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $icons: (
"Google DoubleClick": $iconPath + "DOUBLECLICK16x16.png",
"Google Tag Manager": $iconPath + "GOOGLETAGMANAGER16x16.png",
"LinkedIn Conversion": $iconPath + "LINKEDINPIXEL16x16.png",
"Lytics": $iconPath + "LYTICS16x16.png",
"Matomo": $iconPath + "MATOMO16x16.png",
"Mparticle": $iconPath + "MPARTICLE16x16.png",
"Optimizely X": $iconPath + "OPTIMIZELY16x16.png",
Expand Down
203 changes: 203 additions & 0 deletions src/providers/Lytics.js
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
115 changes: 115 additions & 0 deletions test/providers/Lytics.js
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&currency=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&currency=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&currency=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");



});
Loading

0 comments on commit 3f823b6

Please sign in to comment.