@phantomstudios/ft-lib 0.5.0-rc1 → 0.5.0-rc10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/lib/FTTracking/index.d.ts +3 -0
- package/lib/FTTracking/index.d.ts.map +1 -1
- package/lib/FTTracking/index.js +14 -1
- package/lib/FTTracking/index.js.map +1 -1
- package/lib/cmp/loadFtCmp.js +5 -5
- package/lib/cmp/loadFtCmp.js.map +1 -1
- package/lib/consentMonitor/index.d.ts +2 -0
- package/lib/consentMonitor/index.d.ts.map +1 -1
- package/lib/consentMonitor/index.js +31 -1
- package/lib/consentMonitor/index.js.map +1 -1
- package/package.json +3 -1
- package/src/FTTracking/index.ts +20 -3
- package/src/cmp/loadFtCmp.ts +4 -4
- package/src/consentMonitor/index.ts +33 -2
- package/src/types.d.ts +11 -0
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v18.18.0
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConsentMonitor } from "../consentMonitor";
|
|
1
2
|
import { gaTracker } from "../gaTracker";
|
|
2
3
|
import { oTracker } from "../oTracker";
|
|
3
4
|
import { ScrollTracker } from "../utils/scroll";
|
|
@@ -18,12 +19,14 @@ export declare class FTTracking {
|
|
|
18
19
|
scrollTracker: ScrollTracker;
|
|
19
20
|
disableAppFormatTransform: boolean;
|
|
20
21
|
logValidationErrors: boolean;
|
|
22
|
+
consentMonitor: ConsentMonitor | undefined;
|
|
21
23
|
oEvent: (detail: OrigamiEventType) => void;
|
|
22
24
|
gaEvent: (category: string, action: string, label: string) => void;
|
|
23
25
|
gtmEvent: (category: string, action: string, label: string) => void;
|
|
24
26
|
constructor(config: ConfigType, options?: TrackingOptions);
|
|
25
27
|
set config(c: ConfigType);
|
|
26
28
|
get config(): ConfigType;
|
|
29
|
+
initializeConsentMonitor: () => ConsentMonitor;
|
|
27
30
|
newPageView(config: ConfigType): void;
|
|
28
31
|
}
|
|
29
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,UAAU,EACV,gBAAgB,EAEjB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AASD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,yBAAyB,EAAE,OAAO,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC;IAC3C,MAAM,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;gBAExD,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,eAAe;IA2BzD,IAAI,MAAM,CAAC,CAAC,EAAE,UAAU,EAGvB;IACD,IAAI,MAAM,IAJI,UAAU,CAMvB;IAED,wBAAwB,uBAQtB;IAEK,WAAW,CAAC,MAAM,EAAE,UAAU;CAkBtC"}
|
package/lib/FTTracking/index.js
CHANGED
|
@@ -25,6 +25,16 @@ var DEFAULT_OPTIONS = {
|
|
|
25
25
|
};
|
|
26
26
|
var FTTracking = /** @class */ (function () {
|
|
27
27
|
function FTTracking(config, options) {
|
|
28
|
+
var _this = this;
|
|
29
|
+
this.initializeConsentMonitor = function () {
|
|
30
|
+
if (!_this.consentMonitor) {
|
|
31
|
+
_this.consentMonitor = new consentMonitor_1.ConsentMonitor(window.location.hostname, [
|
|
32
|
+
".app",
|
|
33
|
+
"preview",
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
return _this.consentMonitor;
|
|
37
|
+
};
|
|
28
38
|
this.options = __assign(__assign({}, DEFAULT_OPTIONS), options);
|
|
29
39
|
this.oTracker = new oTracker_1.oTracker(config, this.options);
|
|
30
40
|
this.gaTracker = new gaTracker_1.gaTracker(this.options);
|
|
@@ -41,7 +51,10 @@ var FTTracking = /** @class */ (function () {
|
|
|
41
51
|
this.scrollTracker = new scroll_1.ScrollTracker(this);
|
|
42
52
|
//cookie consent monitor for permutive tracking
|
|
43
53
|
window.addEventListener("load", function () {
|
|
44
|
-
new consentMonitor_1.ConsentMonitor(window.location.hostname, [
|
|
54
|
+
_this.consentMonitor = new consentMonitor_1.ConsentMonitor(window.location.hostname, [
|
|
55
|
+
".app",
|
|
56
|
+
"preview",
|
|
57
|
+
]);
|
|
45
58
|
});
|
|
46
59
|
}
|
|
47
60
|
Object.defineProperty(FTTracking.prototype, "config", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAG2B;AAC3B,0CAAyC;AACzC,wCAAuC;AACvC,0CAAgD;AAChD,sDAI+B;AAW/B,IAAM,eAAe,GAAG;IACtB,qBAAqB,EAAE,mBAAmB;IAC1C,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;IACvB,kBAAkB,EAAE,IAAI;CACzB,CAAC;AAEF;IAaE,oBAAY,MAAkB,EAAE,OAAyB;QAAzD,iBA0BC;QASD,6BAAwB,GAAG;YACzB,IAAI,CAAC,KAAI,CAAC,cAAc,EAAE,CAAC;gBACzB,KAAI,CAAC,cAAc,GAAG,IAAI,+BAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE;oBACjE,MAAM;oBACN,SAAS;iBACV,CAAC,CAAC;YACL,CAAC;YACD,OAAO,KAAI,CAAC,cAAc,CAAC;QAC7B,CAAC,CAAC;QA1CA,IAAI,CAAC,OAAO,yBAAQ,eAAe,GAAK,OAAO,CAAE,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,yBAAyB;YAC5B,IAAI,CAAC,OAAO,CAAC,yBAAyB,IAAI,KAAK,CAAC;QAClD,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,IAAI,KAAK,CAAC;QAErE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;QAC5C,IA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CAAC,iBAAiB,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC;QACD,mDAAmD;IACrD,CAAC;IACH,iBAAC;AAAD,CAAC,AA5ED,IA4EC;AA5EY,gCAAU"}
|
package/lib/cmp/loadFtCmp.js
CHANGED
|
@@ -12,8 +12,8 @@ function loadFtCmpScript() {
|
|
|
12
12
|
script.async = true;
|
|
13
13
|
script.src = "https://consent-notice.ft.com/cmp.js";
|
|
14
14
|
script.referrerPolicy = window.location.hostname.endsWith(".ft.com")
|
|
15
|
-
? "
|
|
16
|
-
: "
|
|
15
|
+
? "" // production hosts
|
|
16
|
+
: "no-referrer-when-downgrade"; // localhost / preview
|
|
17
17
|
script.onload = function () { return resolve(); };
|
|
18
18
|
script.onerror = function () {
|
|
19
19
|
return reject(new Error("Sourcepoint CMP script failed to load"));
|
|
@@ -24,8 +24,8 @@ function loadFtCmpScript() {
|
|
|
24
24
|
function enqueueCmpCallback(cb) {
|
|
25
25
|
if (!window._sp_)
|
|
26
26
|
window._sp_ = {};
|
|
27
|
-
if (!window.
|
|
28
|
-
window.
|
|
29
|
-
window.
|
|
27
|
+
if (!window._sp_queue)
|
|
28
|
+
window._sp_queue = [];
|
|
29
|
+
window._sp_queue.push(cb);
|
|
30
30
|
}
|
|
31
31
|
//# sourceMappingURL=loadFtCmp.js.map
|
package/lib/cmp/loadFtCmp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadFtCmp.js","sourceRoot":"","sources":["../../src/cmp/loadFtCmp.ts"],"names":[],"mappings":";;AAAA,0CAoBC;AAED,gDAKC;AA3BD,SAAgB,eAAe;IAC7B,IAAI,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,CAAC;QAC7C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,C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A0D,CAAC;QAE7D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,kBAAkB,CAAC,EAAc;IAC/C,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IAE7C,MAAM,CAAC,SAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -8,10 +8,12 @@ export declare class ConsentMonitor {
|
|
|
8
8
|
get isDevEnvironment(): boolean;
|
|
9
9
|
get isInitialized(): boolean;
|
|
10
10
|
get userHasConsented(): boolean;
|
|
11
|
+
getCookieValue: (name: string) => string;
|
|
11
12
|
constructor(hostname?: string, devHosts?: string[] | string);
|
|
12
13
|
private attachCmpListeners;
|
|
13
14
|
private enablePermutive;
|
|
14
15
|
private disablePermutive;
|
|
16
|
+
cookieConsentTest: () => void;
|
|
15
17
|
}
|
|
16
18
|
export { ConsentMonitor as consentMonitor };
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consentMonitor/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consentMonitor/index.ts"],"names":[],"mappings":"AA2BA,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,cAAc,CAAS;IAE/B,IAAW,OAAO,IAAI,OAAO,CAE5B;IACD,IAAW,QAAQ,IAAI,MAAM,EAAE,CAE9B;IACD,IAAW,gBAAgB,IAAI,OAAO,CAErC;IACD,IAAW,aAAa,IAAI,OAAO,CAElC;IAED,IAAW,gBAAgB,IAAI,OAAO,CAErC;IAED,cAAc,GAAI,MAAM,MAAM,YACgD;gBAElE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM;IA6B3D,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAQxB,iBAAiB,aAcf;CACH;AAED,OAAO,EAAE,cAAc,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.consentMonitor = exports.ConsentMonitor = void 0;
|
|
16
|
+
var cmp_client_1 = require("@financial-times/cmp-client");
|
|
16
17
|
var debug_1 = __importDefault(require("debug"));
|
|
17
18
|
var loadFtCmp_1 = require("../cmp/loadFtCmp");
|
|
18
19
|
var debug = (0, debug_1.default)("@phantomstudios/ft-lib/consentMonitor");
|
|
@@ -25,6 +26,25 @@ var ConsentMonitor = /** @class */ (function () {
|
|
|
25
26
|
this._consent = false;
|
|
26
27
|
this._isDevEnvironment = false;
|
|
27
28
|
this._isInitialized = false;
|
|
29
|
+
this.getCookieValue = function (name) { var _a; return ((_a = document.cookie.match("(^|;)\\s*" + name + "\\s*=\\s*([^;]+)")) === null || _a === void 0 ? void 0 : _a.pop()) || ""; };
|
|
30
|
+
//check for FTConsent - cookiesOnSite to trigger custom consent_update event for GTM tags (banner updated)
|
|
31
|
+
this.cookieConsentTest = function () {
|
|
32
|
+
if (!_this._isInitialized || !window || !window.dataLayer)
|
|
33
|
+
return;
|
|
34
|
+
if (_this.getCookieValue("FTConsent").includes("cookiesOnsite%3Aon")) {
|
|
35
|
+
//send consent_update event
|
|
36
|
+
window.dataLayer.push({
|
|
37
|
+
event: "consent_update",
|
|
38
|
+
consent: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
window.dataLayer.push({
|
|
43
|
+
event: "consent_update",
|
|
44
|
+
consent: false,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
28
48
|
if (Array.isArray(devHosts)) {
|
|
29
49
|
this._devHosts = __spreadArray(__spreadArray([], devHosts, true), DEFAULT_DEV_HOSTS, true);
|
|
30
50
|
}
|
|
@@ -41,7 +61,13 @@ var ConsentMonitor = /** @class */ (function () {
|
|
|
41
61
|
(0, loadFtCmp_1.loadFtCmpScript)()
|
|
42
62
|
.then(function () {
|
|
43
63
|
_this.attachCmpListeners();
|
|
44
|
-
|
|
64
|
+
// const propertyConfig = window.location.hostname.endsWith("ft.com")
|
|
65
|
+
// ? properties["FT_DOTCOM_PROD"]
|
|
66
|
+
// : properties["FT_DOTCOM_TEST"];
|
|
67
|
+
// initialize CMP - duplicate?
|
|
68
|
+
//initSourcepointCmp({ propertyConfig });
|
|
69
|
+
// use cmp client lib to intercept footer 'Manage Cookies' links (opens privacy modal)
|
|
70
|
+
// Note, function requires very specific link: text = 'Manage Cookies' and href = 'https://ft.com/preferences/manage-cookies'
|
|
45
71
|
})
|
|
46
72
|
.catch(function (err) { return console.error(err); });
|
|
47
73
|
}
|
|
@@ -99,9 +125,13 @@ var ConsentMonitor = /** @class */ (function () {
|
|
|
99
125
|
_this.enablePermutive();
|
|
100
126
|
else if (typeId === CMP_CHOICE_REJECT_ALL)
|
|
101
127
|
_this.disablePermutive();
|
|
128
|
+
// banner updated - check new cookie value to fire consent_update event
|
|
129
|
+
setTimeout(_this.cookieConsentTest, 3000);
|
|
102
130
|
};
|
|
103
131
|
(_b = (_a = window._sp_).addEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, "onConsentReady", onReady);
|
|
104
132
|
(_e = (_d = window._sp_).addEventListener) === null || _e === void 0 ? void 0 : _e.call(_d, "onMessageChoiceSelect", onChoice);
|
|
133
|
+
_this._isInitialized = true;
|
|
134
|
+
(0, cmp_client_1.interceptManageCookiesLinks)();
|
|
105
135
|
});
|
|
106
136
|
};
|
|
107
137
|
ConsentMonitor.prototype.enablePermutive = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consentMonitor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAA0B;AAE1B,8CAAuE;AAEvE,IAAM,KAAK,GAAG,IAAA,eAAK,EAAC,uCAAuC,CAAC,CAAC;AAE7D,IAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAiBlE,IAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,IAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consentMonitor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA0E;AAC1E,gDAA0B;AAE1B,8CAAuE;AAEvE,IAAM,KAAK,GAAG,IAAA,eAAK,EAAC,uCAAuC,CAAC,CAAC;AAE7D,IAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAiBlE,IAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,IAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;IA0BE,wBAAY,QAAiB,EAAE,QAA4B;QAA3D,iBA2BC;QApDO,aAAQ,GAAG,KAAK,CAAC;QAEjB,sBAAiB,GAAG,KAAK,CAAC;QAC1B,mBAAc,GAAG,KAAK,CAAC;QAmB/B,mBAAc,GAAG,UAAC,IAAY,YAC5B,OAAA,CAAA,MAAA,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,GAAG,kBAAkB,CAAC,0CAAE,GAAG,EAAE,KAAI,EAAE,CAAA,EAAA,CAAC;QAyE9E,0GAA0G;QAC1G,sBAAiB,G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EAAuE;gBACvE,UAAU,CAAC,KAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAC3C,CAAC,CAAC;YACF,MAAA,MAAA,MAAM,CAAC,IAAI,EAAC,gBAAgB,mDAAG,gBAAgB,EAAE,OAAO,CAAC,CAAC;YAC1D,MAAA,MAAA,MAAM,CAAC,IAAI,EAAC,gBAAgB,mDAAG,uBAAuB,EAAE,QAAQ,CAAC,CAAC;YAClE,KAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAA,wCAA2B,GAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,wCAAe,GAAvB;;QACE,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC/B,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,CAAC;YACxB,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,yBAAyB;SACjC,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAEO,yCAAgB,GAAxB;;QACE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC3B,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAChC,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAkBH,qBAAC;AAAD,CAAC,AAjHD,IAiHC;AAjHY,wCAAc;AAmHA,wCAAc"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantomstudios/ft-lib",
|
|
3
3
|
"description": "A collection of Javascript UI & tracking utils for FT sites",
|
|
4
|
-
"version": "0.5.0-
|
|
4
|
+
"version": "0.5.0-rc10",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/phantomstudios/ft-lib#readme",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@eslint/compat": "^1.2.9",
|
|
42
42
|
"@eslint/eslintrc": "^3.3.1",
|
|
43
43
|
"@eslint/js": "^9.25.1",
|
|
44
|
+
"@financial-times/cmp-client": "^6.1.2",
|
|
44
45
|
"@financial-times/o-footer": "^9.2.10",
|
|
45
46
|
"@financial-times/o-header": "^11.2.0",
|
|
46
47
|
"@financial-times/o-tracking": "^4.9.0",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
"yup": "^1.0.2"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
77
|
+
"@financial-times/cmp-client": "^6.1.2",
|
|
76
78
|
"@financial-times/o-tracking": "^4.5.1",
|
|
77
79
|
"@financial-times/o-viewport": "^5.1.2"
|
|
78
80
|
}
|
package/src/FTTracking/index.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ConsentMonitor,
|
|
3
|
+
ConsentMonitor as consentMonitor,
|
|
4
|
+
} from "../consentMonitor";
|
|
2
5
|
import { gaTracker } from "../gaTracker";
|
|
3
6
|
import { oTracker } from "../oTracker";
|
|
4
7
|
import { ScrollTracker } from "../utils/scroll";
|
|
5
8
|
import {
|
|
6
|
-
validateConfig,
|
|
7
9
|
ConfigType,
|
|
8
10
|
OrigamiEventType,
|
|
11
|
+
validateConfig,
|
|
9
12
|
} from "../utils/yupValidator";
|
|
10
13
|
|
|
11
14
|
export interface TrackingOptions {
|
|
@@ -32,6 +35,7 @@ export class FTTracking {
|
|
|
32
35
|
scrollTracker: ScrollTracker;
|
|
33
36
|
disableAppFormatTransform: boolean;
|
|
34
37
|
logValidationErrors: boolean;
|
|
38
|
+
consentMonitor: ConsentMonitor | undefined;
|
|
35
39
|
oEvent: (detail: OrigamiEventType) => void;
|
|
36
40
|
gaEvent: (category: string, action: string, label: string) => void;
|
|
37
41
|
gtmEvent: (category: string, action: string, label: string) => void;
|
|
@@ -57,7 +61,10 @@ export class FTTracking {
|
|
|
57
61
|
|
|
58
62
|
//cookie consent monitor for permutive tracking
|
|
59
63
|
window.addEventListener("load", () => {
|
|
60
|
-
new consentMonitor(window.location.hostname, [
|
|
64
|
+
this.consentMonitor = new consentMonitor(window.location.hostname, [
|
|
65
|
+
".app",
|
|
66
|
+
"preview",
|
|
67
|
+
]);
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
70
|
set config(c: ConfigType) {
|
|
@@ -68,6 +75,16 @@ export class FTTracking {
|
|
|
68
75
|
return this._config;
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
initializeConsentMonitor = () => {
|
|
79
|
+
if (!this.consentMonitor) {
|
|
80
|
+
this.consentMonitor = new consentMonitor(window.location.hostname, [
|
|
81
|
+
".app",
|
|
82
|
+
"preview",
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
return this.consentMonitor;
|
|
86
|
+
};
|
|
87
|
+
|
|
71
88
|
public newPageView(config: ConfigType) {
|
|
72
89
|
//Update passed config to otracker,send pageview events and reset scrollTracker
|
|
73
90
|
validateConfig(
|
package/src/cmp/loadFtCmp.ts
CHANGED
|
@@ -9,8 +9,8 @@ export function loadFtCmpScript(): Promise<void> {
|
|
|
9
9
|
script.async = true;
|
|
10
10
|
script.src = "https://consent-notice.ft.com/cmp.js";
|
|
11
11
|
script.referrerPolicy = window.location.hostname.endsWith(".ft.com")
|
|
12
|
-
? "
|
|
13
|
-
: "
|
|
12
|
+
? "" // production hosts
|
|
13
|
+
: "no-referrer-when-downgrade"; // localhost / preview
|
|
14
14
|
|
|
15
15
|
script.onload = () => resolve();
|
|
16
16
|
script.onerror = () =>
|
|
@@ -22,7 +22,7 @@ export function loadFtCmpScript(): Promise<void> {
|
|
|
22
22
|
|
|
23
23
|
export function enqueueCmpCallback(cb: () => void): void {
|
|
24
24
|
if (!window._sp_) window._sp_ = {};
|
|
25
|
-
if (!window.
|
|
25
|
+
if (!window._sp_queue) window._sp_queue = [];
|
|
26
26
|
|
|
27
|
-
window.
|
|
27
|
+
window._sp_queue!.push(cb);
|
|
28
28
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interceptManageCookiesLinks } from "@financial-times/cmp-client";
|
|
1
2
|
import Debug from "debug";
|
|
2
3
|
|
|
3
4
|
import { enqueueCmpCallback, loadFtCmpScript } from "../cmp/loadFtCmp";
|
|
@@ -47,6 +48,9 @@ export class ConsentMonitor {
|
|
|
47
48
|
return this._consent;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
getCookieValue = (name: string) =>
|
|
52
|
+
document.cookie.match("(^|;)\\s*" + name + "\\s*=\\s*([^;]+)")?.pop() || "";
|
|
53
|
+
|
|
50
54
|
constructor(hostname?: string, devHosts?: string[] | string) {
|
|
51
55
|
if (Array.isArray(devHosts)) {
|
|
52
56
|
this._devHosts = [...devHosts, ...DEFAULT_DEV_HOSTS];
|
|
@@ -64,7 +68,14 @@ export class ConsentMonitor {
|
|
|
64
68
|
loadFtCmpScript()
|
|
65
69
|
.then(() => {
|
|
66
70
|
this.attachCmpListeners();
|
|
67
|
-
|
|
71
|
+
// const propertyConfig = window.location.hostname.endsWith("ft.com")
|
|
72
|
+
// ? properties["FT_DOTCOM_PROD"]
|
|
73
|
+
// : properties["FT_DOTCOM_TEST"];
|
|
74
|
+
|
|
75
|
+
// initialize CMP - duplicate?
|
|
76
|
+
//initSourcepointCmp({ propertyConfig });
|
|
77
|
+
// use cmp client lib to intercept footer 'Manage Cookies' links (opens privacy modal)
|
|
78
|
+
// Note, function requires very specific link: text = 'Manage Cookies' and href = 'https://ft.com/preferences/manage-cookies'
|
|
68
79
|
})
|
|
69
80
|
.catch((err) => console.error(err));
|
|
70
81
|
}
|
|
@@ -84,10 +95,13 @@ export class ConsentMonitor {
|
|
|
84
95
|
debug("onMessageChoiceSelect:", typeId);
|
|
85
96
|
if (typeId === CMP_CHOICE_ACCEPT_ALL) this.enablePermutive();
|
|
86
97
|
else if (typeId === CMP_CHOICE_REJECT_ALL) this.disablePermutive();
|
|
98
|
+
// banner updated - check new cookie value to fire consent_update event
|
|
99
|
+
setTimeout(this.cookieConsentTest, 3000);
|
|
87
100
|
};
|
|
88
|
-
|
|
89
101
|
window._sp_.addEventListener?.("onConsentReady", onReady);
|
|
90
102
|
window._sp_.addEventListener?.("onMessageChoiceSelect", onChoice);
|
|
103
|
+
this._isInitialized = true;
|
|
104
|
+
interceptManageCookiesLinks();
|
|
91
105
|
});
|
|
92
106
|
}
|
|
93
107
|
|
|
@@ -107,6 +121,23 @@ export class ConsentMonitor {
|
|
|
107
121
|
window.permutive?.consent({ opt_in: false });
|
|
108
122
|
this._consent = false;
|
|
109
123
|
}
|
|
124
|
+
|
|
125
|
+
//check for FTConsent - cookiesOnSite to trigger custom consent_update event for GTM tags (banner updated)
|
|
126
|
+
cookieConsentTest = () => {
|
|
127
|
+
if (!this._isInitialized || !window || !window.dataLayer) return;
|
|
128
|
+
if (this.getCookieValue("FTConsent").includes("cookiesOnsite%3Aon")) {
|
|
129
|
+
//send consent_update event
|
|
130
|
+
window.dataLayer.push({
|
|
131
|
+
event: "consent_update",
|
|
132
|
+
consent: true,
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
window.dataLayer.push({
|
|
136
|
+
event: "consent_update",
|
|
137
|
+
consent: false,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
110
141
|
}
|
|
111
142
|
|
|
112
143
|
export { ConsentMonitor as consentMonitor };
|
package/src/types.d.ts
CHANGED
|
@@ -5,6 +5,16 @@ interface ConsentOptions {
|
|
|
5
5
|
opt_in?: boolean;
|
|
6
6
|
token?: string;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
declare module "@financial-times/cmp-client" {
|
|
10
|
+
export function interceptManageCookiesLinks(): void;
|
|
11
|
+
export const properties: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
export function initSourcepointCmp(options?: {
|
|
15
|
+
propertyConfig?: any;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
}
|
|
8
18
|
interface SourcepointCmpAPI {
|
|
9
19
|
queue?: Array<() => void>;
|
|
10
20
|
addEventListener?: (
|
|
@@ -15,6 +25,7 @@ interface SourcepointCmpAPI {
|
|
|
15
25
|
}
|
|
16
26
|
interface Window {
|
|
17
27
|
_sp_: SourcepointCmpAPI;
|
|
28
|
+
_sp_queue?: Array<() => void>;
|
|
18
29
|
dataLayer: any;
|
|
19
30
|
gtag: any;
|
|
20
31
|
permutive: {
|