@codecademy/tracking 1.0.0-alpha.f35aad.0 → 1.0.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.
- package/.eslintrc.json +33 -0
- package/CHANGELOG.md +161 -47
- package/LICENSE +1 -1
- package/babel.config.js +11 -2
- package/package.json +6 -29
- package/project.json +46 -0
- package/tsconfig.json +16 -4
- package/tsconfig.spec.json +9 -0
- package/dist/events/__tests__/track.spec.d.ts +0 -1
- package/dist/events/__tests__/track.spec.js +0 -78
- package/dist/events/__tests__/track.test.d.ts +0 -1
- package/dist/events/__tests__/track.test.js +0 -78
- package/dist/events/__tests__/user.spec.d.ts +0 -1
- package/dist/events/__tests__/user.spec.js +0 -42
- package/dist/events/__tests__/user.test.d.ts +0 -1
- package/dist/events/__tests__/user.test.js +0 -42
- package/dist/events/index.d.ts +0 -3
- package/dist/events/index.js +0 -3
- package/dist/events/track.d.ts +0 -11
- package/dist/events/track.js +0 -88
- package/dist/events/types.d.ts +0 -218
- package/dist/events/types.js +0 -0
- package/dist/events/user.d.ts +0 -2
- package/dist/events/user.js +0 -39
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/integrations/__tests__/conditionallyLoadAnalytics-test.d.ts +0 -1
- package/dist/integrations/__tests__/fetchDestinationsForWriteKey-test.d.ts +0 -1
- package/dist/integrations/__tests__/mapDestinations-test.d.ts +0 -1
- package/dist/integrations/conditionallyLoadAnalytics.d.ts +0 -9
- package/dist/integrations/conditionallyLoadAnalytics.js +0 -24
- package/dist/integrations/consent.d.ts +0 -9
- package/dist/integrations/consent.js +0 -11
- package/dist/integrations/fetchDestinationsForWriteKey.d.ts +0 -6
- package/dist/integrations/fetchDestinationsForWriteKey.js +0 -76
- package/dist/integrations/index.d.ts +0 -27
- package/dist/integrations/index.js +0 -84
- package/dist/integrations/mapDestinations.d.ts +0 -19
- package/dist/integrations/mapDestinations.js +0 -55
- package/dist/integrations/onetrust.d.ts +0 -6
- package/dist/integrations/onetrust.js +0 -51
- package/dist/integrations/runSegmentSnippet.d.ts +0 -1
- package/dist/integrations/runSegmentSnippet.js +0 -86
- package/dist/integrations/types.d.ts +0 -24
- package/dist/integrations/types.js +0 -0
- package/jest.config.js +0 -7
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
|
-
import { createTracker } from '../track';
|
|
14
|
-
var apiBaseUrl = 'https://www.codecademy.com';
|
|
15
|
-
var fakeWindow = {
|
|
16
|
-
location: {
|
|
17
|
-
href: 'https://example.com/',
|
|
18
|
-
pathname: '/',
|
|
19
|
-
search: '?utm_source=twitter'
|
|
20
|
-
},
|
|
21
|
-
document: {
|
|
22
|
-
title: 'Test Title'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(window, 'location', {
|
|
26
|
-
value: fakeWindow.location
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(window.document, 'title', {
|
|
29
|
-
value: fakeWindow.document.title
|
|
30
|
-
});
|
|
31
|
-
var beaconMock = jest.fn();
|
|
32
|
-
Object.defineProperty(navigator, 'sendBeacon', {
|
|
33
|
-
value: beaconMock
|
|
34
|
-
});
|
|
35
|
-
afterEach(function () {
|
|
36
|
-
return jest.resetAllMocks();
|
|
37
|
-
});
|
|
38
|
-
describe('createTracker', function () {
|
|
39
|
-
var testEvent = function testEvent(event) {
|
|
40
|
-
var target = 'test target';
|
|
41
|
-
var page_name = 'test page_name';
|
|
42
|
-
var href = fakeWindow.location.href;
|
|
43
|
-
var track = createTracker({
|
|
44
|
-
apiBaseUrl: apiBaseUrl
|
|
45
|
-
});
|
|
46
|
-
var expectedProps = {
|
|
47
|
-
target: target,
|
|
48
|
-
page_name: page_name,
|
|
49
|
-
href: href
|
|
50
|
-
};
|
|
51
|
-
track[event](expectedProps);
|
|
52
|
-
expect(beaconMock.mock.calls.length).toBe(1);
|
|
53
|
-
expect(beaconMock.mock.calls[0][0]).toBe("".concat(apiBaseUrl, "/analytics/user?utm_source=twitter"));
|
|
54
|
-
var formData = beaconMock.mock.calls[0][1];
|
|
55
|
-
expect(formData).toBeInstanceOf(FormData);
|
|
56
|
-
expect(formData.get('category')).toBe('user');
|
|
57
|
-
expect(formData.get('event')).toBe(event);
|
|
58
|
-
expect(formData.has('properties')).toBe(true);
|
|
59
|
-
var actualProps = JSON.parse(formData.get('properties'));
|
|
60
|
-
|
|
61
|
-
for (var _i2 = 0, _Object$entries = Object.entries(expectedProps); _i2 < _Object$entries.length; _i2++) {
|
|
62
|
-
var _ref3 = _Object$entries[_i2];
|
|
63
|
-
|
|
64
|
-
var _ref2 = _slicedToArray(_ref3, 2);
|
|
65
|
-
|
|
66
|
-
var k = _ref2[0];
|
|
67
|
-
var v = _ref2[1];
|
|
68
|
-
expect(actualProps[k]).toBe(v);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
test('click', function () {
|
|
73
|
-
testEvent('click');
|
|
74
|
-
});
|
|
75
|
-
test('visit', function () {
|
|
76
|
-
testEvent('visit');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
|
-
import { createTracker } from '../track';
|
|
14
|
-
var apiBaseUrl = 'https://www.codecademy.com';
|
|
15
|
-
var fakeWindow = {
|
|
16
|
-
location: {
|
|
17
|
-
href: 'https://example.com/',
|
|
18
|
-
pathname: '/',
|
|
19
|
-
search: '?utm_source=twitter'
|
|
20
|
-
},
|
|
21
|
-
document: {
|
|
22
|
-
title: 'Test Title'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(window, 'location', {
|
|
26
|
-
value: fakeWindow.location
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(window.document, 'title', {
|
|
29
|
-
value: fakeWindow.document.title
|
|
30
|
-
});
|
|
31
|
-
var beaconMock = jest.fn();
|
|
32
|
-
Object.defineProperty(navigator, 'sendBeacon', {
|
|
33
|
-
value: beaconMock
|
|
34
|
-
});
|
|
35
|
-
afterEach(function () {
|
|
36
|
-
return jest.resetAllMocks();
|
|
37
|
-
});
|
|
38
|
-
describe('createTracker', function () {
|
|
39
|
-
var testEvent = function testEvent(event) {
|
|
40
|
-
var target = 'test target';
|
|
41
|
-
var page_name = 'test page_name';
|
|
42
|
-
var href = fakeWindow.location.href;
|
|
43
|
-
var track = createTracker({
|
|
44
|
-
apiBaseUrl: apiBaseUrl
|
|
45
|
-
});
|
|
46
|
-
var expectedProps = {
|
|
47
|
-
target: target,
|
|
48
|
-
page_name: page_name,
|
|
49
|
-
href: href
|
|
50
|
-
};
|
|
51
|
-
track[event](expectedProps);
|
|
52
|
-
expect(beaconMock.mock.calls.length).toBe(1);
|
|
53
|
-
expect(beaconMock.mock.calls[0][0]).toBe("".concat(apiBaseUrl, "/analytics/user?utm_source=twitter"));
|
|
54
|
-
var formData = beaconMock.mock.calls[0][1];
|
|
55
|
-
expect(formData).toBeInstanceOf(FormData);
|
|
56
|
-
expect(formData.get('category')).toBe('user');
|
|
57
|
-
expect(formData.get('event')).toBe(event);
|
|
58
|
-
expect(formData.has('properties')).toBe(true);
|
|
59
|
-
var actualProps = JSON.parse(formData.get('properties'));
|
|
60
|
-
|
|
61
|
-
for (var _i2 = 0, _Object$entries = Object.entries(expectedProps); _i2 < _Object$entries.length; _i2++) {
|
|
62
|
-
var _ref3 = _Object$entries[_i2];
|
|
63
|
-
|
|
64
|
-
var _ref2 = _slicedToArray(_ref3, 2);
|
|
65
|
-
|
|
66
|
-
var k = _ref2[0];
|
|
67
|
-
var v = _ref2[1];
|
|
68
|
-
expect(actualProps[k]).toBe(v);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
test('click', function () {
|
|
73
|
-
testEvent('click');
|
|
74
|
-
});
|
|
75
|
-
test('visit', function () {
|
|
76
|
-
testEvent('visit');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -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 +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
|
-
});
|
package/dist/events/index.d.ts
DELETED
package/dist/events/index.js
DELETED
package/dist/events/track.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { EventDataTypes, TrackingOptions, UserClickData, UserVisitData } from './types';
|
|
2
|
-
export declare type TrackerOptions = {
|
|
3
|
-
apiBaseUrl: string;
|
|
4
|
-
verbose?: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare const createTracker: ({ apiBaseUrl, verbose }: TrackerOptions) => {
|
|
7
|
-
event: <Category extends keyof EventDataTypes, Event_1 extends string & keyof EventDataTypes[Category], Data extends EventDataTypes[Category][Event_1]>(category: Category, event: Event_1, userData: Data, options?: TrackingOptions) => void;
|
|
8
|
-
click: (data: UserClickData) => void;
|
|
9
|
-
visit: (data: UserVisitData) => void;
|
|
10
|
-
pushDataLayerEvent: (eventName: string) => void;
|
|
11
|
-
};
|
package/dist/events/track.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
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; }
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
-
|
|
9
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
-
|
|
15
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
16
|
-
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
|
|
19
|
-
/* eslint-disable no-console */
|
|
20
|
-
export var createTracker = function createTracker(_ref) {
|
|
21
|
-
var apiBaseUrl = _ref.apiBaseUrl,
|
|
22
|
-
verbose = _ref.verbose;
|
|
23
|
-
|
|
24
|
-
var beacon = function beacon(endpoint, data) {
|
|
25
|
-
var uri = new URL(endpoint, apiBaseUrl);
|
|
26
|
-
var form = new FormData();
|
|
27
|
-
|
|
28
|
-
for (var _i2 = 0, _Object$entries = Object.entries(data); _i2 < _Object$entries.length; _i2++) {
|
|
29
|
-
var _ref4 = _Object$entries[_i2];
|
|
30
|
-
|
|
31
|
-
var _ref3 = _slicedToArray(_ref4, 2);
|
|
32
|
-
|
|
33
|
-
var k = _ref3[0];
|
|
34
|
-
var v = _ref3[1];
|
|
35
|
-
form.append(k, v.toString());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
navigator.sendBeacon(uri.toString(), form);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
var event = function event(category, _event, userData) {
|
|
42
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
43
|
-
|
|
44
|
-
var properties = _objectSpread(_objectSpread({}, userData), {}, {
|
|
45
|
-
fullpath: window.location.pathname + window.location.search,
|
|
46
|
-
search: window.location.search,
|
|
47
|
-
path: window.location.pathname,
|
|
48
|
-
title: window.document.title,
|
|
49
|
-
url: window.location.href
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (verbose) {
|
|
53
|
-
console.groupCollapsed("%cTracking Event Fired: ".concat(category, ":").concat(_event), 'color: #4b35ef; font-style: italic;');
|
|
54
|
-
console.log({
|
|
55
|
-
category: category,
|
|
56
|
-
event: _event,
|
|
57
|
-
properties: properties
|
|
58
|
-
});
|
|
59
|
-
console.groupEnd();
|
|
60
|
-
} // This allows the UTM query params to get registered in the user session.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var queryParams = window.location.search;
|
|
64
|
-
beacon("/analytics/".concat(category).concat(queryParams), {
|
|
65
|
-
category: category,
|
|
66
|
-
event: _event,
|
|
67
|
-
properties: JSON.stringify(properties),
|
|
68
|
-
gdpr_safe: "".concat(options.gdprSafe)
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
event: event,
|
|
74
|
-
click: function click(data) {
|
|
75
|
-
return event('user', 'click', data);
|
|
76
|
-
},
|
|
77
|
-
visit: function visit(data) {
|
|
78
|
-
return event('user', 'visit', data);
|
|
79
|
-
},
|
|
80
|
-
pushDataLayerEvent: function pushDataLayerEvent(eventName) {
|
|
81
|
-
var _ref5;
|
|
82
|
-
|
|
83
|
-
((_ref5 = window).dataLayer || (_ref5.dataLayer = [])).push({
|
|
84
|
-
event: eventName
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
};
|
package/dist/events/types.d.ts
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Data types for all of our events.
|
|
3
|
-
* Follows the format EventDataTypes[Category].[Event].EventData
|
|
4
|
-
* Category + Event gives the corresponding event table in redshift
|
|
5
|
-
*/
|
|
6
|
-
export declare type EventDataTypes = {
|
|
7
|
-
user: {
|
|
8
|
-
click: UserClickData;
|
|
9
|
-
visit: UserVisitData;
|
|
10
|
-
impression: BaseEventAnyData;
|
|
11
|
-
email_trigger: BaseEventAnyData;
|
|
12
|
-
content_completed: BaseEventAnyData;
|
|
13
|
-
submit: BaseEventAnyData;
|
|
14
|
-
workspace_init: BaseEventAnyData;
|
|
15
|
-
meaningful_content_loaded: BaseEventAnyData;
|
|
16
|
-
practice_completed: BaseEventAnyData;
|
|
17
|
-
};
|
|
18
|
-
ad: {
|
|
19
|
-
click: BaseEventAnyData;
|
|
20
|
-
impression: BaseEventAnyData;
|
|
21
|
-
};
|
|
22
|
-
calendar: {
|
|
23
|
-
reminder: BaseEventAnyData;
|
|
24
|
-
};
|
|
25
|
-
notification: {
|
|
26
|
-
clicked: BaseEventAnyData;
|
|
27
|
-
ion: BaseEventAnyData;
|
|
28
|
-
};
|
|
29
|
-
form: {
|
|
30
|
-
submit: BaseEventAnyData;
|
|
31
|
-
};
|
|
32
|
-
sorting_quiz: {
|
|
33
|
-
result: BaseEventAnyData;
|
|
34
|
-
impression: BaseEventAnyData;
|
|
35
|
-
answer: EventAnswerData;
|
|
36
|
-
};
|
|
37
|
-
onboarding_survey: {
|
|
38
|
-
answer: BaseEventAnyData;
|
|
39
|
-
recommendation: BaseEventAnyData;
|
|
40
|
-
user_selected_recommendation: BaseEventAnyData;
|
|
41
|
-
};
|
|
42
|
-
exercise: {
|
|
43
|
-
force_pass: BaseEventAnyData;
|
|
44
|
-
};
|
|
45
|
-
payments: {
|
|
46
|
-
cancel_survey: BaseEventAnyData;
|
|
47
|
-
};
|
|
48
|
-
search: {
|
|
49
|
-
visit: BaseEventAnyData;
|
|
50
|
-
click: BaseEventAnyData;
|
|
51
|
-
query: BaseEventAnyData;
|
|
52
|
-
result: BaseEventAnyData;
|
|
53
|
-
};
|
|
54
|
-
page: {
|
|
55
|
-
career_path_visited: PagePathVisitedData;
|
|
56
|
-
skill_path_visited: PagePathVisitedData;
|
|
57
|
-
course_page_visited: CoursePageVisitedData;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Base event data shared by all events
|
|
62
|
-
*/
|
|
63
|
-
export declare type BaseEventData = {
|
|
64
|
-
fullpath?: null;
|
|
65
|
-
search?: null;
|
|
66
|
-
path?: null;
|
|
67
|
-
title?: null;
|
|
68
|
-
url?: null;
|
|
69
|
-
id?: null;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Generic type to use for event data not typed yet
|
|
73
|
-
*/
|
|
74
|
-
export declare type BaseEventAnyData = BaseEventData & {
|
|
75
|
-
[key: string]: any;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Options to pass to the tracking function
|
|
79
|
-
*/
|
|
80
|
-
export declare type TrackingOptions = {
|
|
81
|
-
/** tells backend not to merge user-identifying data onto the event payload */
|
|
82
|
-
gdprSafe?: boolean;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* The Content IDs related to the current event, to help build the content context of the event.
|
|
86
|
-
* These IDs get hashed into a single value and overwrite content_id before they are sent to
|
|
87
|
-
* redshift in lib/content_group_id.rb
|
|
88
|
-
*/
|
|
89
|
-
export declare type TrackingContentIds = {
|
|
90
|
-
assessment_id?: string;
|
|
91
|
-
content_item_id?: string;
|
|
92
|
-
exercise_id?: string;
|
|
93
|
-
learning_standard_id?: string;
|
|
94
|
-
module_id?: string;
|
|
95
|
-
path_id?: string;
|
|
96
|
-
program_id?: string;
|
|
97
|
-
program_unit_id?: string;
|
|
98
|
-
review_card_id?: string;
|
|
99
|
-
track_id?: string;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Shared data relevant for all user events
|
|
103
|
-
*/
|
|
104
|
-
export declare type UserSharedData = BaseEventData & {
|
|
105
|
-
/** the click target of the event */
|
|
106
|
-
target?: string;
|
|
107
|
-
/** the page the event is coming from */
|
|
108
|
-
page_name?: string;
|
|
109
|
-
/** a context id for the event, for events that occur in more than one place */
|
|
110
|
-
context?: string;
|
|
111
|
-
/** the link being clicked on */
|
|
112
|
-
href?: string;
|
|
113
|
-
/** a version id for the element (ex. different version ids for redesigns) */
|
|
114
|
-
version?: string;
|
|
115
|
-
content_ids?: TrackingContentIds;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Data sent to user click event table
|
|
119
|
-
* NOTE: avoid adding additional properties to these objects
|
|
120
|
-
* Instead, reuse existing properties, or make any additional properties generic so that they can be reused.
|
|
121
|
-
* https://www.notion.so/codecademy/Guide-to-Event-Tracking-Schema-5d40b09a297743f7a30a2690208194c8#800bbf6cdf2e44de9823cd75bcc574e5
|
|
122
|
-
*/
|
|
123
|
-
export declare type UserClickData = UserSharedData & {
|
|
124
|
-
target: string;
|
|
125
|
-
id?: string;
|
|
126
|
-
distinct_id?: string;
|
|
127
|
-
content_id?: string;
|
|
128
|
-
slug?: string;
|
|
129
|
-
name?: string;
|
|
130
|
-
action?: string;
|
|
131
|
-
type?: string;
|
|
132
|
-
location?: string;
|
|
133
|
-
element?: string;
|
|
134
|
-
weekly_goal?: string | number;
|
|
135
|
-
complete?: string;
|
|
136
|
-
video_url?: string;
|
|
137
|
-
path_id?: string;
|
|
138
|
-
path_slug?: string;
|
|
139
|
-
event_name?: string;
|
|
140
|
-
onboarding_entrypoint?: string;
|
|
141
|
-
content_slug?: string;
|
|
142
|
-
module_id?: string;
|
|
143
|
-
track_slug?: string;
|
|
144
|
-
module_slug?: string;
|
|
145
|
-
button?: string;
|
|
146
|
-
current_challenge_day?: string | number;
|
|
147
|
-
track_id?: string;
|
|
148
|
-
course?: string;
|
|
149
|
-
path_name?: string;
|
|
150
|
-
event_id?: string;
|
|
151
|
-
unit?: string;
|
|
152
|
-
lesson?: string;
|
|
153
|
-
community_prompt?: string;
|
|
154
|
-
contentItem?: any;
|
|
155
|
-
unit_slug?: string;
|
|
156
|
-
course_slug?: string;
|
|
157
|
-
course_progress?: number;
|
|
158
|
-
assessment_id?: string;
|
|
159
|
-
container_slugs?: string[];
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Data sent to user visit event table
|
|
163
|
-
* NOTE: avoid adding additional properties to these objects
|
|
164
|
-
* Instead, reuse existing properties, or make any additional properties generic so that they can be reused.
|
|
165
|
-
* https://www.notion.so/codecademy/Guide-to-Event-Tracking-Schema-5d40b09a297743f7a30a2690208194c8#800bbf6cdf2e44de9823cd75bcc574e5
|
|
166
|
-
*/
|
|
167
|
-
export declare type UserVisitData = UserSharedData & {
|
|
168
|
-
page_name: string;
|
|
169
|
-
category?: string;
|
|
170
|
-
distinct_id?: string;
|
|
171
|
-
type?: string;
|
|
172
|
-
target?: string;
|
|
173
|
-
section?: string;
|
|
174
|
-
plan?: string;
|
|
175
|
-
path_id?: string;
|
|
176
|
-
post?: string;
|
|
177
|
-
story_type?: string;
|
|
178
|
-
path_title?: string;
|
|
179
|
-
onboarding_entrypoint?: string;
|
|
180
|
-
course_slug?: string;
|
|
181
|
-
course?: string;
|
|
182
|
-
interstitial_name?: string;
|
|
183
|
-
content_id?: string;
|
|
184
|
-
story_slug?: string;
|
|
185
|
-
unit?: string;
|
|
186
|
-
lesson?: string;
|
|
187
|
-
};
|
|
188
|
-
export declare type EventAnswerData = BaseEventData & {
|
|
189
|
-
question_index: number;
|
|
190
|
-
answer_index: number;
|
|
191
|
-
answer: any;
|
|
192
|
-
answer_slug: string;
|
|
193
|
-
};
|
|
194
|
-
export declare type User = {
|
|
195
|
-
id?: string;
|
|
196
|
-
auth_token: string;
|
|
197
|
-
profile_image_url?: string;
|
|
198
|
-
email?: string;
|
|
199
|
-
is_pro?: boolean;
|
|
200
|
-
username?: string;
|
|
201
|
-
location: {
|
|
202
|
-
in_eu: boolean;
|
|
203
|
-
geo_country: string;
|
|
204
|
-
};
|
|
205
|
-
features: string[];
|
|
206
|
-
};
|
|
207
|
-
export declare type UseUserResponse = {
|
|
208
|
-
user?: User;
|
|
209
|
-
status: string;
|
|
210
|
-
};
|
|
211
|
-
export declare type PagePathVisitedData = BaseEventData & {
|
|
212
|
-
path_id: string;
|
|
213
|
-
path_full_title: string;
|
|
214
|
-
};
|
|
215
|
-
export declare type CoursePageVisitedData = BaseEventData & {
|
|
216
|
-
course_id: string;
|
|
217
|
-
course_full_title: string;
|
|
218
|
-
};
|
package/dist/events/types.js
DELETED
|
File without changes
|
package/dist/events/user.d.ts
DELETED
package/dist/events/user.js
DELETED
|
@@ -1,39 +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
|
-
export var fetchUser = /*#__PURE__*/function () {
|
|
8
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(apiBaseUrl) {
|
|
9
|
-
var response;
|
|
10
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
|
-
while (1) {
|
|
12
|
-
switch (_context.prev = _context.next) {
|
|
13
|
-
case 0:
|
|
14
|
-
_context.next = 2;
|
|
15
|
-
return fetch("".concat(apiBaseUrl, "/users/web"), {
|
|
16
|
-
method: 'GET',
|
|
17
|
-
headers: {
|
|
18
|
-
'Content-type': 'application/json',
|
|
19
|
-
Accept: 'application/json'
|
|
20
|
-
},
|
|
21
|
-
credentials: 'include'
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
case 2:
|
|
25
|
-
response = _context.sent;
|
|
26
|
-
return _context.abrupt("return", response.json());
|
|
27
|
-
|
|
28
|
-
case 4:
|
|
29
|
-
case "end":
|
|
30
|
-
return _context.stop();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}, _callee);
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
return function fetchUser(_x) {
|
|
37
|
-
return _ref.apply(this, arguments);
|
|
38
|
-
};
|
|
39
|
-
}();
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SegmentAnalytics, UserIntegrationSummary } from './types';
|
|
2
|
-
export declare type AnalyticsLoadOptions = {
|
|
3
|
-
analytics: SegmentAnalytics;
|
|
4
|
-
destinationPreferences: Record<string, boolean>;
|
|
5
|
-
identifyPreferences: Record<string, boolean>;
|
|
6
|
-
user?: UserIntegrationSummary;
|
|
7
|
-
writeKey: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const conditionallyLoadAnalytics: ({ analytics, destinationPreferences, identifyPreferences, user, writeKey, }: AnalyticsLoadOptions) => void;
|