-
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
Showing
4 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
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,123 @@ | ||
/** | ||
* Comscore | ||
* https://direct.comscore.com/clients/help/FAQ.aspx#faqTagging | ||
* | ||
* @class | ||
* @extends BaseProvider | ||
*/ | ||
|
||
class ComscoreProvider extends BaseProvider { | ||
constructor() { | ||
super(); | ||
this._key = "COMSCORE"; | ||
this._pattern = /sb\.scorecardresearch\.com.+(?<!\.js)$/; | ||
this._name = "Comscore"; | ||
this._type = "marketing"; | ||
} | ||
|
||
/** | ||
* Retrieve the column mappings for default columns (account, event type) | ||
* | ||
* @return {{}} | ||
*/ | ||
get columnMapping() { | ||
return { | ||
account: "c2", | ||
requestType: "requestType" | ||
}; | ||
} | ||
|
||
/** | ||
* Retrieve the group names & order | ||
* | ||
* @returns {*[]} | ||
*/ | ||
get groups() { | ||
return [ | ||
{ | ||
key: "general", | ||
name: "General" | ||
}, | ||
{ | ||
key: "custom", | ||
name: "Custom" | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* Get all of the available URL parameter keys | ||
* | ||
* @returns {{}} | ||
*/ | ||
get keys() { | ||
return { | ||
c1: { | ||
name: "Tag Type", | ||
group: "general" | ||
}, | ||
c2: { | ||
name: "Client ID", | ||
group: "general" | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Parse a given URL parameter into human-readable form | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
* | ||
* @returns {void|{}} | ||
*/ | ||
handleQueryParam(name, value) { | ||
let result = {}; | ||
|
||
if (name.startsWith("c")) { | ||
result = { | ||
key: name, | ||
field: name, | ||
value: value, | ||
group: "custom" | ||
}; | ||
} else { | ||
result = super.handleQueryParam(name, value); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Parse custom properties for a given URL | ||
* | ||
* @param {string} url | ||
* @param {object} params | ||
* | ||
* @returns {Array} | ||
*/ | ||
handleCustom(url, params) { | ||
let results = [], | ||
c1 = params.get("c1"), | ||
c2 = params.get("c2"); | ||
|
||
if (c1) { | ||
results.push({ | ||
key: "tagType", | ||
field: "Tag Type", | ||
value: c1, | ||
group: "general" | ||
}); | ||
} | ||
|
||
if (c2) { | ||
results.push({ | ||
key: "clientID", | ||
field: "Client ID", | ||
value: c2, | ||
group: "general" | ||
}); | ||
} | ||
|
||
return results; | ||
} | ||
} |
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,119 @@ | ||
import test from "ava"; | ||
|
||
import { default as ComscoreProvider } from "./../source/providers/Comscore.js"; | ||
import { OmnibugProvider } from "./../source/providers.js"; | ||
|
||
test("Generic Comscore Provider Information", t => { | ||
let provider = new ComscoreProvider(); | ||
t.is(provider.key, "COMSCORE", "Key should always be COMSCORE"); | ||
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("Pattern should match Comscore event requests", t => { | ||
let provider = new ComscoreProvider(), | ||
url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
t.true(provider.checkUrl(url)); | ||
|
||
t.false( | ||
provider.checkUrl("https://omnibug.io/testing"), | ||
"Provider should not match on non-provider based URLs" | ||
); | ||
}); | ||
|
||
test("OmnibugProvider returns ComscoreProvider", t => { | ||
let url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
let results = OmnibugProvider.parseUrl(url); | ||
t.true( | ||
typeof results === "object" && results !== null, | ||
"Results is a non-null object" | ||
); | ||
t.is(results.provider.key, "COMSCORE", "Results provider is Comscore"); | ||
}); | ||
|
||
test("Provider returns client ID code", t => { | ||
let provider = new ComscoreProvider(), | ||
url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
let results = provider.parseUrl(url), | ||
clientID = results.data.find(result => { | ||
return result.key === "clientID"; | ||
}); | ||
|
||
t.is(typeof clientID, "object", "clientID exists"); | ||
t.is(clientID.field, "Client ID", "Field is Client ID"); | ||
t.is(clientID.value, "123456789", "Client Code value is correct"); | ||
t.is(clientID.group, "general", "Client ID group is general"); | ||
}); | ||
|
||
test("Provider returns tag type", t => { | ||
let provider = new ComscoreProvider(), | ||
url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
let results = provider.parseUrl(url), | ||
tagType = results.data.find(result => { | ||
return result.key === "tagType"; | ||
}); | ||
|
||
t.is(typeof tagType, "object", "tagType exists"); | ||
t.is(tagType.field, "Tag Type", "Field is Tag Type"); | ||
t.is(tagType.value, "2", "Tag Type value is correct"); | ||
t.is(tagType.group, "general", "Tag Type group is general"); | ||
}); | ||
|
||
test("Custom parameters group populates with c parameters", t => { | ||
let provider = new ComscoreProvider(), | ||
url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
let results = provider.parseUrl(url); | ||
let c4 = results.data.find(result => { | ||
return result.key === "c4"; | ||
}), | ||
cv = results.data.find(result => { | ||
return result.key === "cv"; | ||
}); | ||
|
||
t.is(typeof c4, "object", "c4 data is an object"); | ||
t.is(c4.field, "c4", "c4 is field value"); | ||
t.is( | ||
c4.value, | ||
"https://www.example.com", | ||
"c4 value is https://www.example.com" | ||
); | ||
t.is(c4.group, "custom", "c4 is in custom group"); | ||
|
||
t.is(typeof cv, "object", "cv data is an object"); | ||
t.is(cv.field, "cv", "cv is field value"); | ||
t.is(cv.value, "2.0", "cv value is 2.0"); | ||
t.is(cv.group, "custom", "cv is in custom group"); | ||
}); | ||
|
||
test("Other parameters group populates with non-c parameters", t => { | ||
let provider = new ComscoreProvider(), | ||
url = | ||
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com"; | ||
|
||
let results = provider.parseUrl(url); | ||
let ns_type = results.data.find(result => { | ||
return result.key === "ns_type"; | ||
}); | ||
|
||
t.is(typeof ns_type, "object", "ns_type data is an object"); | ||
t.is(ns_type.field, "ns_type", "ns_type is field value"); | ||
t.is(ns_type.value, "hidden", "ns_type value is hidden"); | ||
t.is(ns_type.group, "other", "ns_type is in other group"); | ||
}); |