@codecademy/tracking 1.0.26-alpha.0a3a8b2ca8.0 → 1.0.26-alpha.1f6ff1576e.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.
@@ -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
16
  verbose = _ref.verbose;
23
17
  const beacon = (endpoint, data) => {
24
- const uri = extendURLAsString(apiBaseUrl, endpoint);
18
+ const _URL = new URL(apiBaseUrl),
19
+ origin = _URL.origin;
20
+ const uri = new URL(endpoint, origin).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,9 @@ export const createTracker = _ref => {
50
46
  }));
51
47
  };
52
48
  const serverSideBeacon = (endpoint, data) => {
53
- const uri = extendURLAsString(apiBaseUrl, endpoint);
49
+ const _URL2 = new URL(apiBaseUrl),
50
+ origin = _URL2.origin;
51
+ const uri = new URL(endpoint, origin).toString();
54
52
  const form = new URLSearchParams();
55
53
  for (const _ref4 of Object.entries(data)) {
56
54
  var _ref5 = _slicedToArray(_ref4, 2);
@@ -84,17 +82,22 @@ export const createTracker = _ref => {
84
82
  });
85
83
  console.groupEnd();
86
84
  }
85
+
86
+ // Use /analytics path if path is not already specified in apiBaseUrl
87
+ const _URL3 = new URL(apiBaseUrl),
88
+ pathname = _URL3.pathname;
89
+ const basePath = pathname === '/' ? '/analytics' : pathname;
87
90
  if (typeof window !== 'undefined') {
88
91
  // This allows the UTM query params to get registered in the user session.
89
92
  const queryParams = window.location.search;
90
- beacon("/".concat(category).concat(queryParams), {
93
+ beacon("".concat(basePath, "/").concat(category).concat(queryParams), {
91
94
  category,
92
95
  event,
93
96
  properties: JSON.stringify(properties),
94
97
  gdpr_safe: "".concat(options.gdprSafe)
95
98
  });
96
99
  } else {
97
- serverSideBeacon("/".concat(category), {
100
+ serverSideBeacon("".concat(basePath, "/").concat(category), {
98
101
  category,
99
102
  event,
100
103
  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.0a3a8b2ca8.0",
4
+ "version": "1.0.26-alpha.1f6ff1576e.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": "c7197d0e94d0545ffce83dd69d0c04399596cfea"
16
+ "gitHead": "6d7621abdb0a4bda78b64746cf2ca1cf94c08b52"
17
17
  }