@codecademy/tracking 0.26.0 → 0.26.1-alpha.0193907f0.0

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.
@@ -1,136 +0,0 @@
1
- var _class, _temp;
2
-
3
- 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; }
4
-
5
- function _objectSpread(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; }
6
-
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- 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; }
10
-
11
- import { createTracker } from '../track';
12
- var apiBaseUrl = 'https://www.codecademy.com';
13
- var fakeWindow = {
14
- location: {
15
- href: 'https://example.com/',
16
- pathname: '/catalog',
17
- search: '?utm_source=twitter'
18
- },
19
- document: {
20
- title: 'Test Title'
21
- }
22
- };
23
- var mockFetch = jest.fn();
24
- Object.defineProperties(window, {
25
- fetch: {
26
- value: mockFetch
27
- },
28
- location: {
29
- value: fakeWindow.location
30
- },
31
- Request: {
32
- value: (_temp = _class = function MockRequest() {
33
- _classCallCheck(this, MockRequest);
34
- }, _defineProperty(_class, "keepalive", true), _temp)
35
- }
36
- });
37
- Object.defineProperty(window.document, 'title', {
38
- value: fakeWindow.document.title
39
- });
40
- afterEach(function () {
41
- return jest.resetAllMocks();
42
- });
43
- var mockClientType = jest.fn();
44
- jest.mock('../../integrations/device', function () {
45
- return {
46
- get getClientType() {
47
- return mockClientType;
48
- }
49
-
50
- };
51
- });
52
- describe('createTracker', function () {
53
- var describeEvent = function describeEvent(event) {
54
- describe(event, function () {
55
- var target = 'test target';
56
- var page_name = 'test page_name';
57
- var href = fakeWindow.location.href;
58
- var tracker = createTracker({
59
- apiBaseUrl: apiBaseUrl
60
- });
61
- var expectedProps = {
62
- target: target,
63
- page_name: page_name,
64
- href: href
65
- };
66
- it('calls only to beacon when it exists', function () {
67
- var mockBeacon = jest.fn().mockReturnValueOnce(true);
68
- mockClientType.mockReturnValue('default');
69
- Object.defineProperty(navigator, 'sendBeacon', {
70
- writable: true,
71
- value: mockBeacon
72
- });
73
- tracker[event](expectedProps);
74
- expect(mockBeacon).toHaveBeenCalledTimes(1);
75
- expect(mockBeacon).toHaveBeenCalledWith("".concat(apiBaseUrl, "/analytics/user?utm_source=twitter"), expect.any(FormData));
76
- var formData = mockBeacon.mock.calls[0][1];
77
- expect(Object.fromEntries(formData)).toEqual(expect.objectContaining({
78
- category: 'user',
79
- event: event,
80
- gdpr_safe: 'undefined'
81
- }));
82
- expect(JSON.parse(formData.get('properties'))).toEqual(_objectSpread(_objectSpread({}, expectedProps), {}, {
83
- fullpath: window.location.pathname + window.location.search,
84
- path: window.location.pathname,
85
- referrer: '',
86
- search: window.location.search,
87
- title: document.title,
88
- url: window.location.href,
89
- client: 'default'
90
- }));
91
- expect(fetch).not.toHaveBeenCalled();
92
- });
93
- it('calls to fetch when beacon does not exist', function () {
94
- Object.defineProperty(navigator, 'sendBeacon', {
95
- writable: true,
96
- value: undefined
97
- });
98
- tracker[event](expectedProps);
99
- expect(fetch).toHaveBeenCalledWith('https://www.codecademy.com/analytics/user?utm_source=twitter', {
100
- body: expect.any(FormData),
101
- method: 'POST'
102
- });
103
- });
104
- it('calls to fetch when beacon returns false', function () {
105
- Object.defineProperty(navigator, 'sendBeacon', {
106
- writable: true,
107
- value: function value() {
108
- return false;
109
- }
110
- });
111
- tracker[event](expectedProps);
112
- expect(fetch).toHaveBeenCalledWith('https://www.codecademy.com/analytics/user?utm_source=twitter', {
113
- body: expect.any(FormData),
114
- method: 'POST'
115
- });
116
- });
117
- it('calls to fetch when beacon throws an error', function () {
118
- Object.defineProperty(navigator, 'sendBeacon', {
119
- writable: true,
120
- value: function value() {
121
- throw new Error('Oh no!');
122
- }
123
- });
124
- tracker[event](expectedProps);
125
- expect(fetch).toHaveBeenCalledWith('https://www.codecademy.com/analytics/user?utm_source=twitter', {
126
- body: expect.any(FormData),
127
- method: 'POST'
128
- });
129
- });
130
- });
131
- };
132
-
133
- describeEvent('click');
134
- describeEvent('impression');
135
- describeEvent('visit');
136
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
- import fetch from 'fetch-mock';
8
- import { fetchUser } from '../user';
9
- var apiBaseUrl = 'https://www.codecademy.com';
10
- var authUser = {
11
- foo: 'bar'
12
- };
13
- describe('fetchUser', function () {
14
- afterEach(function () {
15
- return fetch.restore();
16
- });
17
- test('retrieves a user', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
18
- var user;
19
- return _regeneratorRuntime.wrap(function _callee$(_context) {
20
- while (1) {
21
- switch (_context.prev = _context.next) {
22
- case 0:
23
- fetch.getOnce('*', JSON.stringify(authUser));
24
- _context.next = 3;
25
- return fetchUser(apiBaseUrl);
26
-
27
- case 3:
28
- user = _context.sent;
29
- expect(user).toEqual(authUser);
30
- expect(fetch.calls().length).toEqual(1);
31
- expect(fetch.calls()[0][0]).toBe("".concat(apiBaseUrl, "/users/web"));
32
- expect(fetch.calls()[0][1].method).toBe('GET');
33
- expect(fetch.calls()[0][1].credentials).toBe('include');
34
-
35
- case 9:
36
- case "end":
37
- return _context.stop();
38
- }
39
- }
40
- }, _callee);
41
- })));
42
- });
@@ -1,58 +0,0 @@
1
- import { Consent } from '../consent';
2
- import { getConsentDecision, OPT_OUT_DATALAYER_VAR } from '../getConsentDecision';
3
- var MINIMUM_CONSENT = [Consent.StrictlyNecessary];
4
- var FULL_CONSENT = [Consent.StrictlyNecessary, Consent.Functional, Consent.Performance, Consent.Targeting];
5
- var FULL_CONSENT_STRING = [','].concat(FULL_CONSENT).join(',');
6
- describe('getConsentDecision', function () {
7
- it('converts a stringified consent decision into an array', function () {
8
- var result = getConsentDecision({
9
- scope: {
10
- OnetrustActiveGroups: FULL_CONSENT_STRING
11
- }
12
- });
13
- expect(result).toEqual(FULL_CONSENT);
14
- });
15
- it('does not modify an array formatted consent decision', function () {
16
- var result = getConsentDecision({
17
- scope: {
18
- OnetrustActiveGroups: FULL_CONSENT
19
- }
20
- });
21
- expect(result).toEqual(FULL_CONSENT);
22
- });
23
- describe('optedOutExternalTracking', function () {
24
- it('reduces the consent decision to necessary and functional for opted out users', function () {
25
- var result = getConsentDecision({
26
- scope: {
27
- OnetrustActiveGroups: FULL_CONSENT
28
- },
29
- optedOutExternalTracking: true
30
- });
31
- expect(result).toEqual([Consent.StrictlyNecessary, Consent.Functional]);
32
- });
33
- it('does not add Functional tracking if the user has opted out of it', function () {
34
- var result = getConsentDecision({
35
- scope: {
36
- OnetrustActiveGroups: MINIMUM_CONSENT
37
- },
38
- optedOutExternalTracking: true
39
- });
40
- expect(result).toEqual(MINIMUM_CONSENT);
41
- });
42
- it('triggers the opt out datalayer variable', function () {
43
- var _scope$dataLayer;
44
-
45
- var scope = {
46
- OnetrustActiveGroups: FULL_CONSENT
47
- };
48
- getConsentDecision({
49
- scope: scope,
50
- optedOutExternalTracking: true
51
- });
52
- var dataLayerVars = (_scope$dataLayer = scope.dataLayer) === null || _scope$dataLayer === void 0 ? void 0 : _scope$dataLayer.map(function (v) {
53
- return Object.keys(v);
54
- }).flat();
55
- expect(dataLayerVars).toEqual([OPT_OUT_DATALAYER_VAR]);
56
- });
57
- });
58
- });
@@ -1 +0,0 @@
1
- export {};
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('../../jest.config.base')('tracking');