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