@codecademy/tracking 1.0.25 → 1.0.26-alpha.0a3a8b2ca8.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,11 +11,17 @@ 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
+ };
14
20
  export const createTracker = _ref => {
15
21
  let apiBaseUrl = _ref.apiBaseUrl,
16
22
  verbose = _ref.verbose;
17
23
  const beacon = (endpoint, data) => {
18
- const uri = new URL(endpoint, apiBaseUrl).toString();
24
+ const uri = extendURLAsString(apiBaseUrl, endpoint);
19
25
  const form = new FormData();
20
26
  for (const _ref2 of Object.entries(data)) {
21
27
  var _ref3 = _slicedToArray(_ref2, 2);
@@ -44,7 +50,7 @@ export const createTracker = _ref => {
44
50
  }));
45
51
  };
46
52
  const serverSideBeacon = (endpoint, data) => {
47
- const uri = new URL(endpoint, apiBaseUrl).toString();
53
+ const uri = extendURLAsString(apiBaseUrl, endpoint);
48
54
  const form = new URLSearchParams();
49
55
  for (const _ref4 of Object.entries(data)) {
50
56
  var _ref5 = _slicedToArray(_ref4, 2);
@@ -81,14 +87,14 @@ export const createTracker = _ref => {
81
87
  if (typeof window !== 'undefined') {
82
88
  // This allows the UTM query params to get registered in the user session.
83
89
  const queryParams = window.location.search;
84
- beacon("/analytics/".concat(category).concat(queryParams), {
90
+ beacon("/".concat(category).concat(queryParams), {
85
91
  category,
86
92
  event,
87
93
  properties: JSON.stringify(properties),
88
94
  gdpr_safe: "".concat(options.gdprSafe)
89
95
  });
90
96
  } else {
91
- serverSideBeacon("/analytics/".concat(category), {
97
+ serverSideBeacon("/".concat(category), {
92
98
  category,
93
99
  event,
94
100
  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.25",
4
+ "version": "1.0.26-alpha.0a3a8b2ca8.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": "0d28f029ebd80f33036a831b41d6cf8186437b05"
16
+ "gitHead": "c7197d0e94d0545ffce83dd69d0c04399596cfea"
17
17
  }