From 38615b0edb79cd7358e0a847beab7a74ddfeba14 Mon Sep 17 00:00:00 2001 From: ioanna0 Date: Wed, 7 Oct 2020 12:15:51 +0100 Subject: [PATCH] added twitter and lotame 3pts --- .eslintrc | 1 + .../external-scripts/lotame-script.ts | 25 +++++++++++++++ .../external-scripts/twitter-script.ts | 27 ++++++++++++++++ src/third-party-tags/lotame.spec.ts | 13 ++++++++ src/third-party-tags/lotame.ts | 32 +++++++++++++++++++ src/third-party-tags/permutive.spec.ts | 2 +- src/third-party-tags/twitter-uwt.spec.ts | 12 +++++++ src/third-party-tags/twitter-uwt.ts | 8 +++++ 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/third-party-tags/external-scripts/lotame-script.ts create mode 100644 src/third-party-tags/external-scripts/twitter-script.ts create mode 100644 src/third-party-tags/lotame.spec.ts create mode 100644 src/third-party-tags/lotame.ts create mode 100644 src/third-party-tags/twitter-uwt.spec.ts create mode 100644 src/third-party-tags/twitter-uwt.ts diff --git a/.eslintrc b/.eslintrc index 740e9f634..629ead93a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -23,6 +23,7 @@ "rules": { "eslint-comments/require-description": ["error", { "ignore": [] }], "eslint-comments/disable-enable-pair": 0, + "eslint-comments/no-unlimited-disable": 0, "import/no-default-export": 2, "import/prefer-default-export": 0, "import/newline-after-import": 2, diff --git a/src/third-party-tags/external-scripts/lotame-script.ts b/src/third-party-tags/external-scripts/lotame-script.ts new file mode 100644 index 000000000..ec36ee0b3 --- /dev/null +++ b/src/third-party-tags/external-scripts/lotame-script.ts @@ -0,0 +1,25 @@ +/* eslint-disable -- this is third party code */ +// @ts-nocheck +// More details here: https://my.lotame.com/t/g9hxvnw/detailed-reference-guide + +export const lotameScript = (callback) => { + !(function() { + var lotameTagInput = { + data: {}, + config: { + clientId: 12666, + onProfileReady: function(o) { + callback(o); + } + }, + }; + + // Lotame initialization + var lotameConfig = lotameTagInput.config || {}; + var namespace = (window['lotame_' + lotameConfig.clientId] = {}); + namespace.config = lotameConfig; + namespace.data = lotameTagInput.data || {}; + namespace.cmd = namespace.cmd || []; + })(); +}; +/* eslint-enable */ diff --git a/src/third-party-tags/external-scripts/twitter-script.ts b/src/third-party-tags/external-scripts/twitter-script.ts new file mode 100644 index 000000000..c4385bbc8 --- /dev/null +++ b/src/third-party-tags/external-scripts/twitter-script.ts @@ -0,0 +1,27 @@ +/* eslint-disable -- this is third party code */ +// @ts-nocheck +// Twitter universal website tag code +// How to set up conversion tracking: https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html + +export const twitterScript = () => { + !(function (e, t, n, s, u, a) { + e.twq || + ((s = e.twq = function () { + s.exe ? s.exe(...arguments) : s.queue.push(arguments); + }), + (s.version = '1.1'), + (s.queue = []), + (u = t.createElement(n)), + (u.async = !0), + (u.src = '//static.ads-twitter.com/uwt.js'), + (a = t.getElementsByTagName(n)[0]), + a.parentNode.insertBefore(u, a)); + })(window, document, 'script'); + // Insert Twitter Pixel ID and Standard Event data below + twq('init', 'nyl43'); // The Guardian ID + twq('track', 'PageView'); + + twq('init', 'ny4k9'); // PHD ID + twq('track', 'PageView') +}; +/* eslint-enable */ diff --git a/src/third-party-tags/lotame.spec.ts b/src/third-party-tags/lotame.spec.ts new file mode 100644 index 000000000..3ddceadff --- /dev/null +++ b/src/third-party-tags/lotame.spec.ts @@ -0,0 +1,13 @@ +import { lotame } from './lotame'; + +describe('lotame', () => { + it('construct lotame with correct params', () => { + const lotameTag = lotame({ shouldRun: true }); + expect(lotameTag).toStrictEqual({ + shouldRun: true, + url: '//tags.crwdcntrl.net/lt/c/12666/lt.min.js', + beforeLoad: lotameTag.beforeLoad, + name: 'lotame', + }); + }); +}); diff --git a/src/third-party-tags/lotame.ts b/src/third-party-tags/lotame.ts new file mode 100644 index 000000000..5dc5d65fb --- /dev/null +++ b/src/third-party-tags/lotame.ts @@ -0,0 +1,32 @@ +import { GetThirdPartyTag } from '../types'; +import { lotameScript } from './external-scripts/lotame-script'; + +export type LotameData = { + ozoneLotameData: Array; + ozoneLotameProfileId: string; +}; + +let lotameData: LotameData; + +const ozoneLotameCallback = (obj: { + getAudiences: () => Array; + getProfileId: () => string; +}) => { + lotameData = { + ozoneLotameData: obj.getAudiences(), + ozoneLotameProfileId: obj.getProfileId(), + }; +}; + +const beforeLoad = () => { + lotameScript(ozoneLotameCallback); +}; + +export const getLotameData: () => LotameData = () => lotameData; + +export const lotame: GetThirdPartyTag = ({ shouldRun }) => ({ + shouldRun, + url: '//tags.crwdcntrl.net/lt/c/12666/lt.min.js', + beforeLoad, + name: 'lotame', +}); diff --git a/src/third-party-tags/permutive.spec.ts b/src/third-party-tags/permutive.spec.ts index ab5236b65..06c0ee6d3 100644 --- a/src/third-party-tags/permutive.spec.ts +++ b/src/third-party-tags/permutive.spec.ts @@ -1,7 +1,7 @@ import { permutive } from './permutive'; describe('permutive', () => { - it('should use the feature swtich option', () => { + it('should construct permutive with correct params', () => { expect(permutive({ shouldRun: true })).toStrictEqual({ shouldRun: true, url: '//cdn.permutive.com/d6691a17-6fdb-4d26-85d6-b3dd27f55f08-web.js', diff --git a/src/third-party-tags/twitter-uwt.spec.ts b/src/third-party-tags/twitter-uwt.spec.ts new file mode 100644 index 000000000..5d799ff11 --- /dev/null +++ b/src/third-party-tags/twitter-uwt.spec.ts @@ -0,0 +1,12 @@ +import { twitterScript } from './external-scripts/twitter-script'; +import { twitter } from './twitter-uwt'; + +describe('twitter', () => { + it('construct twitter pixel with correct params', () => { + expect(twitter({ shouldRun: true })).toStrictEqual({ + shouldRun: true, + name: 'twitter', + insertSnippet: twitterScript, + }); + }); +}); diff --git a/src/third-party-tags/twitter-uwt.ts b/src/third-party-tags/twitter-uwt.ts new file mode 100644 index 000000000..157ad7586 --- /dev/null +++ b/src/third-party-tags/twitter-uwt.ts @@ -0,0 +1,8 @@ +import { GetThirdPartyTag } from '../types'; +import { twitterScript } from './external-scripts/twitter-script'; + +export const twitter: GetThirdPartyTag = ({ shouldRun }) => ({ + shouldRun, + name: 'twitter', + insertSnippet: twitterScript, +});