@codecademy/tracking 1.0.26-alpha.4c96b81bdf.0 → 1.0.26-alpha.71fc821ee6.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.
@@ -2,8 +2,9 @@ import type { BaseEventData, EventDataTypes, TrackingOptions, UserClickData, Use
2
2
  export type TrackerOptions = {
3
3
  apiBaseUrl: string;
4
4
  verbose?: boolean;
5
+ customUrlPath?: string;
5
6
  };
6
- export declare const createTracker: ({ apiBaseUrl, verbose }: TrackerOptions) => {
7
+ export declare const createTracker: ({ apiBaseUrl, verbose, customUrlPath, }: TrackerOptions) => {
7
8
  event: <Category extends keyof EventDataTypes, Event_1 extends string & keyof EventDataTypes[Category], Data extends EventDataTypes[Category][Event_1] & BaseEventData>(category: Category, event: Event_1, userData: Data, options?: TrackingOptions) => void;
8
9
  click: (data: UserClickData) => void;
9
10
  impression: (data: UserImpressionData) => void;
@@ -11,17 +11,13 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
  import { getClientType } from '../integrations/device';
13
13
  const browserSupportsKeepalive = () => 'keepalive' in window.Request.prototype;
14
- const extendURLAsString = (base, pathsAndArgs) => {
15
- // Trim slashes and add them back to ensure flexible input
16
- base = base.replace(/\/$/, '');
17
- pathsAndArgs = pathsAndArgs.replace(/\/$/, '').replace(/^\//, '');
18
- return new URL(base + '/' + pathsAndArgs).toString();
19
- };
20
14
  export const createTracker = _ref => {
21
15
  let apiBaseUrl = _ref.apiBaseUrl,
22
- verbose = _ref.verbose;
16
+ verbose = _ref.verbose,
17
+ customUrlPath = _ref.customUrlPath;
18
+ console.log("createTracker > customUrlPath: ".concat(customUrlPath));
23
19
  const beacon = (endpoint, data) => {
24
- const uri = extendURLAsString(apiBaseUrl, endpoint);
20
+ const uri = new URL(endpoint, apiBaseUrl).toString();
25
21
  const form = new FormData();
26
22
  for (const _ref2 of Object.entries(data)) {
27
23
  var _ref3 = _slicedToArray(_ref2, 2);
@@ -50,7 +46,7 @@ export const createTracker = _ref => {
50
46
  }));
51
47
  };
52
48
  const serverSideBeacon = (endpoint, data) => {
53
- const uri = extendURLAsString(apiBaseUrl, endpoint);
49
+ const uri = new URL(endpoint, apiBaseUrl).toString();
54
50
  const form = new URLSearchParams();
55
51
  for (const _ref4 of Object.entries(data)) {
56
52
  var _ref5 = _slicedToArray(_ref4, 2);
@@ -84,17 +80,20 @@ export const createTracker = _ref => {
84
80
  });
85
81
  console.groupEnd();
86
82
  }
83
+
84
+ // If present, use custom endpoint and trim starting and ending slashes
85
+ const baseEndpoint = customUrlPath ? customUrlPath.replace(/\/$/, '').replace(/^\//, '') : 'analytics';
87
86
  if (typeof window !== 'undefined') {
88
87
  // This allows the UTM query params to get registered in the user session.
89
88
  const queryParams = window.location.search;
90
- beacon("/".concat(category).concat(queryParams), {
89
+ beacon("/".concat(baseEndpoint, "/").concat(category).concat(queryParams), {
91
90
  category,
92
91
  event,
93
92
  properties: JSON.stringify(properties),
94
93
  gdpr_safe: "".concat(options.gdprSafe)
95
94
  });
96
95
  } else {
97
- serverSideBeacon("/".concat(category), {
96
+ serverSideBeacon("/".concat(baseEndpoint, "/").concat(category), {
98
97
  category,
99
98
  event,
100
99
  properties: JSON.stringify(properties)
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.26-alpha.4c96b81bdf.0",
4
+ "version": "1.0.26-alpha.71fc821ee6.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "files": [
7
7
  "dist/**"
@@ -13,5 +13,5 @@
13
13
  "access": "public"
14
14
  },
15
15
  "repository": "git@github.com:codecademy-engineering/mono.git",
16
- "gitHead": "16579bd789f81746cc26b20013ce630d42b13d24"
16
+ "gitHead": "d4865f1f13514c80bcf36eb057bf60a34c84dbf0"
17
17
  }