@codecademy/tracking 1.0.18 → 1.0.19-alpha.39c6fa2bc7.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/dist/AppTracker.d.ts +21 -0
- package/dist/AppTracker.js +69 -0
- package/dist/__fixtures__/index.d.ts +1 -0
- package/dist/__fixtures__/index.js +1 -0
- package/dist/__fixtures__/mockUseAppTrackerContext.d.ts +8 -0
- package/dist/__fixtures__/mockUseAppTrackerContext.js +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createTracker } from '.';
|
|
3
|
+
type Tracker = ReturnType<typeof createTracker>;
|
|
4
|
+
export interface AppTrackerContextValue {
|
|
5
|
+
trackUserClick: Tracker['click'];
|
|
6
|
+
trackEvent: Tracker['event'];
|
|
7
|
+
trackUserVisit: Tracker['visit'];
|
|
8
|
+
trackUserImpression: Tracker['impression'];
|
|
9
|
+
trackSetFilter: (filter_key: string, filter_value: filterType) => void;
|
|
10
|
+
trackSearchQuery: (search_query: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export type filterType = string | string[] | number | boolean;
|
|
13
|
+
export declare const AppTrackerContext: React.Context<AppTrackerContextValue | undefined>;
|
|
14
|
+
export declare const AppTrackerProvider: React.FC<{
|
|
15
|
+
apiBaseUrl: string;
|
|
16
|
+
verbose: boolean;
|
|
17
|
+
source_codebase: string;
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const useAppTrackerContext: () => AppTrackerContextValue;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import React, { createContext, useContext } from 'react';
|
|
8
|
+
import { createTracker } from '.';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export var AppTrackerContext = /*#__PURE__*/createContext(undefined);
|
|
11
|
+
export var AppTrackerProvider = function AppTrackerProvider(_ref) {
|
|
12
|
+
var children = _ref.children,
|
|
13
|
+
source_codebase = _ref.source_codebase,
|
|
14
|
+
apiBaseUrl = _ref.apiBaseUrl,
|
|
15
|
+
verbose = _ref.verbose;
|
|
16
|
+
var tracker = createTracker({
|
|
17
|
+
apiBaseUrl: apiBaseUrl,
|
|
18
|
+
verbose: verbose
|
|
19
|
+
});
|
|
20
|
+
var trackUserClick = function trackUserClick(data) {
|
|
21
|
+
return tracker.click(_objectSpread(_objectSpread({}, data), {}, {
|
|
22
|
+
source_codebase: source_codebase
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
var trackEvent = function trackEvent(category, event, data) {
|
|
26
|
+
return tracker.event(category, event, _objectSpread(_objectSpread({}, data), {}, {
|
|
27
|
+
source_codebase: source_codebase
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
var trackUserVisit = function trackUserVisit(data) {
|
|
31
|
+
return tracker.visit(_objectSpread(_objectSpread({}, data), {}, {
|
|
32
|
+
source_codebase: source_codebase
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
var trackUserImpression = function trackUserImpression(data) {
|
|
36
|
+
return tracker.impression(_objectSpread(_objectSpread({}, data), {}, {
|
|
37
|
+
source_codebase: source_codebase
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
var trackSetFilter = function trackSetFilter(filter_key, filter_value) {
|
|
41
|
+
return tracker.event('business', 'filter_event', {
|
|
42
|
+
filter_key: filter_key,
|
|
43
|
+
filter_value: filter_value
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
var trackSearchQuery = function trackSearchQuery(search_query) {
|
|
47
|
+
return tracker.event('business', 'search_event', {
|
|
48
|
+
search_query: search_query
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return /*#__PURE__*/_jsx(AppTrackerContext.Provider, {
|
|
52
|
+
value: {
|
|
53
|
+
trackUserClick: trackUserClick,
|
|
54
|
+
trackEvent: trackEvent,
|
|
55
|
+
trackUserVisit: trackUserVisit,
|
|
56
|
+
trackUserImpression: trackUserImpression,
|
|
57
|
+
trackSetFilter: trackSetFilter,
|
|
58
|
+
trackSearchQuery: trackSearchQuery
|
|
59
|
+
},
|
|
60
|
+
children: children
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
export var useAppTrackerContext = function useAppTrackerContext() {
|
|
64
|
+
var context = useContext(AppTrackerContext);
|
|
65
|
+
if (context === undefined) {
|
|
66
|
+
throw new Error('useAppTrackerContext must be used within AppTrackerContext.Provider');
|
|
67
|
+
}
|
|
68
|
+
return context;
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mockUseAppTrackerContext';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mockUseAppTrackerContext';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
export declare const trackUserClick: jest.Mock<any, any, any>;
|
|
3
|
+
export declare const trackEvent: jest.Mock<any, any, any>;
|
|
4
|
+
export declare const trackUserVisit: jest.Mock<any, any, any>;
|
|
5
|
+
export declare const trackUserImpression: jest.Mock<any, any, any>;
|
|
6
|
+
export declare const trackSetFilter: jest.Mock<any, any, any>;
|
|
7
|
+
export declare const trackSearchQuery: jest.Mock<any, any, any>;
|
|
8
|
+
export declare const mockUseAppTrackerContext: jest.Mock<any, any, any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var trackUserClick = jest.fn();
|
|
2
|
+
export var trackEvent = jest.fn();
|
|
3
|
+
export var trackUserVisit = jest.fn();
|
|
4
|
+
export var trackUserImpression = jest.fn();
|
|
5
|
+
export var trackSetFilter = jest.fn();
|
|
6
|
+
export var trackSearchQuery = jest.fn();
|
|
7
|
+
export var mockUseAppTrackerContext = jest.fn().mockReturnValue({
|
|
8
|
+
trackUserClick: trackUserClick,
|
|
9
|
+
trackEvent: trackEvent,
|
|
10
|
+
trackUserVisit: trackUserVisit,
|
|
11
|
+
trackUserImpression: trackUserImpression,
|
|
12
|
+
trackSetFilter: trackSetFilter,
|
|
13
|
+
trackSearchQuery: trackSearchQuery
|
|
14
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/tracking",
|
|
3
3
|
"description": "Tracking library for Codecademy",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.19-alpha.39c6fa2bc7.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist/**"
|
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"module": "./dist/index.js",
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": "^18.2.0"
|
|
14
|
+
},
|
|
12
15
|
"publishConfig": {
|
|
13
16
|
"access": "public"
|
|
14
17
|
},
|
|
15
18
|
"repository": "git@github.com:codecademy-engineering/mono.git",
|
|
16
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "31b134392c322d017c86174f3e73da81a441d4e8"
|
|
17
20
|
}
|