Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/n-tracking

Package Overview
Dependencies
Maintainers
12
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/n-tracking - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

babel.config.js

30

dist/browser.js
import oTracking from '@financial-times/o-tracking';
import oGrid from '@financial-times/o-grid';
import oViewport from '@financial-times/o-viewport';
import { getUsPrivacyForTracking } from '@financial-times/privacy-us-privacy';
import { getPersonalisedConsent } from '@financial-times/ads-personalised-consent';
import { onCLS, onFCP, onFID, onLCP, onTTFB } from 'web-vitals';

@@ -116,2 +118,11 @@ import readyState from 'ready-state';

async function getConsentData() {
const consentValues = (await getPersonalisedConsent()).isAllowed();
const usprivacy = getUsPrivacyForTracking();
return {
...consentValues,
usprivacy,
};
}
function broadcast (name, data, bubbles = true) {

@@ -713,3 +724,3 @@ const rootEl = Element.prototype.isPrototypeOf(this) ? this : document.body;

...appContext,
...extraContext
...extraContext,
}),

@@ -729,6 +740,19 @@ user: getUserData(),

oTracking.page({
const pageViewEventParams = {
...errorPageParams,
...pageViewContext,
});
};
getConsentData()
.then((consents) => {
oTracking.page({
...pageViewEventParams,
consents,
});
})
.catch((err) => {
// eslint-disable-next-line no-console
console.warn("Could not get consent data", err);
oTracking.page(pageViewEventParams);
});
}

@@ -735,0 +759,0 @@

57

dist/server.js

@@ -9,55 +9,2 @@ 'use strict';

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
// For a list of all the properties available see the app context schema:

@@ -85,3 +32,3 @@ // <https://github.com/Financial-Times/dotcom-page-kit/blob/HEAD/packages/dotcom-server-app-context/schema.md>

},
context: _objectSpread2(_objectSpread2({}, context), {}, {
context: { ...context,
product: 'next',

@@ -91,3 +38,3 @@ data: {

}
})
}
};

@@ -94,0 +41,0 @@ const encodedTrackingData = encodeURIComponent(JSON.stringify(trackingData)); // NOTE: This function will be stringified and embedded so use ES5 only!

@@ -6,3 +6,3 @@ {

"browser": "dist/browser.js",
"version": "6.2.0",
"version": "6.3.0",
"license": "MIT",

@@ -40,5 +40,7 @@ "repository": "Financial-Times/n-tracking.git",

"dependencies": {
"@financial-times/ads-personalised-consent": "^5.2.3",
"@financial-times/o-grid": "^5.0.0",
"@financial-times/o-tracking": "^4.5.0",
"@financial-times/o-viewport": "^4.0.0",
"@financial-times/privacy-us-privacy": "^1.0.0",
"ready-state": "^2.0.5",

@@ -45,0 +47,0 @@ "web-vitals": "^3.0.0"

@@ -10,2 +10,3 @@ jest.mock('@financial-times/o-tracking', () => {

jest.mock('@financial-times/o-grid', () => ({ getCurrentLayout: jest.fn() }), { virtual: true });
jest.mock('../utils/getConsentData', () => jest.fn());

@@ -15,2 +16,3 @@ import oTracking from '@financial-times/o-tracking';

import oGrid from '@financial-times/o-grid';
import getConsentData from '../utils/getConsentData';
import { init, SPOOR_API_INGEST_URL } from '..';

@@ -28,4 +30,13 @@

describe('src/index', () => {
afterEach(() => jest.clearAllMocks());
beforeAll(() => {
getConsentData.mockResolvedValue({});
window.console.warn = jest.fn()
})
afterEach(() => {
jest.clearAllMocks();
// Clean global instance left on the window after each init() call
delete window.oTracking
});
describe('.init()', () => {

@@ -45,2 +56,20 @@ it('initialises o-tracking', () => {

it('attaches the o-tracking instance to the window', () => {
const oTrackingInstance = init({ appContext });
expect(window.oTracking).toBe(oTrackingInstance);
});
it("warns the user in case an instance of o-tracking is already attached to the window without overriding the value", () => {
window.oTracking = "initialValue";
const ourInstance = init({ appContext });
expect(window.console.warn).toHaveBeenCalledWith(
"An oTracking instance already exists on window, skipping",
{
currentInstance: 'initialValue',
ourInstance,
}
);
expect(window.oTracking).toBe("initialValue");
});
it('configures o-tracking with context data', () => {

@@ -81,10 +110,31 @@ init({ appContext });

it('triggers a page view with page view context', () => {
it('triggers a page view with page view context and consents', async () => {
getConsentData.mockResolvedValue({ some: 'consentData' });
init({ appContext, pageViewContext: { foo: 'bar' } });
// We don't await the promise returned while getting consent data.
// The line below lets us wait for the mocked getConsentData promise to resolve.
await new Promise(process.nextTick);
expect(oTracking.page).toHaveBeenCalledTimes(1);
expect(oTracking.page).toHaveBeenCalledWith(
expect.objectContaining({
foo: 'bar',
consents: {
some: 'consentData'
},
})
);
});
it('Does not pass consents down if getting consents fails', async () => {
getConsentData.mockRejectedValueOnce(new Error('no consent data'));
init({ appContext, pageViewContext: { foo: 'bar' } });
await new Promise(process.nextTick);
expect(oTracking.page).toHaveBeenCalledTimes(1);
expect(oTracking.page).toHaveBeenCalledWith(
expect.objectContaining({
foo: 'bar'
foo: 'bar',
})

@@ -91,0 +141,0 @@ );

@@ -6,2 +6,3 @@ import oTracking from '@financial-times/o-tracking';

import transformContextData from './utils/transformContextData';
import getConsentData from './utils/getConsentData';

@@ -19,3 +20,3 @@ export const SPOOR_API_INGEST_URL = 'https://spoor-api.ft.com/ingest';

...appContext,
...extraContext
...extraContext,
}),

@@ -35,6 +36,19 @@ user: getUserData(),

oTracking.page({
const pageViewEventParams = {
...errorPageParams,
...pageViewContext,
});
};
getConsentData()
.then((consents) => {
oTracking.page({
...pageViewEventParams,
consents,
});
})
.catch((err) => {
// eslint-disable-next-line no-console
console.warn("Could not get consent data", err);
oTracking.page(pageViewEventParams);
});
}

@@ -41,0 +55,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc