@chordcommerce/analytics 1.14.0 → 1.14.1

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.
@@ -8,15 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { addCdpConsent } from './consent/index.js';
11
+ import { normalizeCDPDomain } from './utils.js';
11
12
  /*
12
13
  * Adds the Chord CDP snippet to the page.
13
14
  */
14
15
  export const addCdpSnippet = (options) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  if (!document || typeof document.createElement === 'undefined')
16
17
  return;
18
+ const normalizedCDPDomain = normalizeCDPDomain(options.cdpDomain);
17
19
  const s = document.createElement('script');
18
20
  s.async = true;
19
- s.src = `${options.cdpDomain}/p.js`;
21
+ s.src = `${normalizedCDPDomain}/p.js`;
20
22
  s.setAttribute('data-debug', `${!!options.debug}`);
21
23
  s.setAttribute('data-init-only', 'true');
22
24
  s.setAttribute('data-namespace', `_${options.namespace}`);
@@ -0,0 +1 @@
1
+ export declare function normalizeCDPDomain(cdpDomain: string): string;
@@ -0,0 +1,8 @@
1
+ export function normalizeCDPDomain(cdpDomain) {
2
+ let domain = cdpDomain.replace(/\/+$/, '');
3
+ if (domain.endsWith('/p.js')) {
4
+ domain = domain.slice(0, -'/p.js'.length);
5
+ domain = domain.replace(/\/+$/, '');
6
+ }
7
+ return domain;
8
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chordcommerce/analytics",
3
3
  "description": "Chord Commerce event tracking",
4
- "version": "1.14.0",
4
+ "version": "1.14.1",
5
5
  "author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",