Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added twitter pixel & lotame #41

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions src/third-party-tags/external-scripts/lotame-script.ts
Original file line number Diff line number Diff line change
@@ -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 */
27 changes: 27 additions & 0 deletions src/third-party-tags/external-scripts/twitter-script.ts
Original file line number Diff line number Diff line change
@@ -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 */
13 changes: 13 additions & 0 deletions src/third-party-tags/lotame.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
32 changes: 32 additions & 0 deletions src/third-party-tags/lotame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { GetThirdPartyTag } from '../types';
import { lotameScript } from './external-scripts/lotame-script';

export type LotameData = {
ozoneLotameData: Array<string>;
ozoneLotameProfileId: string;
};

let lotameData: LotameData;

const ozoneLotameCallback = (obj: {
getAudiences: () => Array<string>;
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',
});
2 changes: 1 addition & 1 deletion src/third-party-tags/permutive.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
12 changes: 12 additions & 0 deletions src/third-party-tags/twitter-uwt.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});
});
8 changes: 8 additions & 0 deletions src/third-party-tags/twitter-uwt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { GetThirdPartyTag } from '../types';
import { twitterScript as insertSnippet } from './external-scripts/twitter-script';

export const twitter: GetThirdPartyTag = ({ shouldRun }) => ({
shouldRun,
name: 'twitter',
insertSnippet,
});