Skip to content

Commit db82313

Browse files
longstoryshortKiara Daswani
andauthored
Added support of the consent flag parameter cs_ucfr, updated beacon.j… (#623)
* Added support of the consent flag parameter cs_ucfr, updated beacon.js link * updated formatting in line 98+ * removed '@segment/analytics.js-integration/lib/statics' dependency * Bump version to 3.0.0 due to tag url change * cs_ucfr flag maps properties and context object, nested attributes, US Privacy string * fixed 2 unit tests Co-authored-by: Kiara Daswani <kiara.daswani@Kiaras-MBP.attlocal.net>
1 parent 7a6bca0 commit db82313

File tree

3 files changed

+357
-8
lines changed

3 files changed

+357
-8
lines changed

integrations/comscore/lib/index.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var integration = require('@segment/analytics.js-integration');
88
var useHttps = require('use-https');
9+
var trample = require('@segment/trample');
910

1011
/**
1112
* Expose `Comscore` integration.
@@ -17,8 +18,9 @@ var Comscore = (module.exports = integration('comScore')
1718
.option('c1', '2')
1819
.option('c2', '')
1920
.option('comscorekw', '')
20-
.tag('http', '<script src="http://b.scorecardresearch.com/beacon.js">')
21-
.tag('https', '<script src="https://sb.scorecardresearch.com/beacon.js">'));
21+
.option('consentFlag', '')
22+
.tag('https', '<script src="https://sb.scorecardresearch.com/cs/{{ c2 }}/beacon.js">')
23+
.tag('http', '<script src="https://sb.scorecardresearch.com/cs/{{ c2 }}/beacon.js">'));
2224

2325
/**
2426
* Initialize.
@@ -78,6 +80,9 @@ Comscore.prototype._initialize = function() {
7880
Comscore.prototype.mapComscoreParams = function(page) {
7981
var beaconParamMap = this.options.beaconParamMap;
8082
var properties = page.properties();
83+
var flatProperties = trample(page.properties());
84+
var flatContext = trample(page.context());
85+
var consentValue;
8186

8287
var comScoreParams = {};
8388

@@ -89,6 +94,40 @@ Comscore.prototype.mapComscoreParams = function(page) {
8994
}
9095
});
9196

97+
if (this.options.consentFlag) {
98+
if (flatProperties.hasOwnProperty(this.options.consentFlag)) {
99+
consentValue = page.proxy('properties.' + this.options.consentFlag)
100+
} else if (flatContext.hasOwnProperty(this.options.consentFlag)) {
101+
consentValue = page.proxy('context.' + this.options.consentFlag)
102+
}
103+
if (
104+
consentValue !== undefined &&
105+
!(
106+
String(consentValue).match(/^1(-|Y|N){3}/g) &&
107+
String(consentValue).split('')[2] === '-'
108+
)
109+
) {
110+
if (
111+
String(consentValue) === 'true' ||
112+
String(consentValue) === '1' ||
113+
(String(consentValue).match(/^1(-|Y|N){3}/g) &&
114+
String(consentValue).split('')[2] === 'N')
115+
) {
116+
consentValue = '1';
117+
} else if (
118+
String(consentValue) === 'false' ||
119+
String(consentValue) === '0' ||
120+
(String(consentValue).match(/^1(-|Y|N){3}/g) &&
121+
String(consentValue).split('')[2] === 'Y')
122+
) {
123+
consentValue = '0';
124+
} else {
125+
consentValue = '';
126+
}
127+
comScoreParams.cs_ucfr = consentValue;
128+
}
129+
}
130+
92131
comScoreParams.c1 = this.options.c1;
93132
comScoreParams.c2 = this.options.c2;
94133
if (this.options.comscorekw.length) {

integrations/comscore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-comscore",
33
"description": "The Comscore analytics.js integration.",
4-
"version": "2.1.1",
4+
"version": "3.0.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

0 commit comments

Comments
 (0)