@chordcommerce/analytics 1.24.2 → 1.24.3

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.
@@ -171,7 +171,7 @@ var addCdpConsent = function (options) {
171
171
  * or null if consent setup failed or was blocked.
172
172
  */
173
173
  var init = function () { return __awaiter(void 0, void 0, void 0, function () {
174
- var canBeTracked, error_2;
174
+ var canBeTracked, error_2, error_3;
175
175
  return __generator(this, function (_a) {
176
176
  switch (_a.label) {
177
177
  case 0:
@@ -182,29 +182,38 @@ var addCdpConsent = function (options) {
182
182
  console.error("Consent management adapter \"".concat(options.consent, "\" is not supported."));
183
183
  return [2 /*return*/, null];
184
184
  }
185
- if (!options.awaitConsent) return [3 /*break*/, 2];
185
+ if (!options.awaitConsent) return [3 /*break*/, 6];
186
186
  if (options.debug && options.enableLogging) {
187
187
  console.log('[Chord Analytics DEBUG]: awaitConsent is true, checking if user can be tracked');
188
188
  }
189
189
  return [4 /*yield*/, checkUserCanBeTracked()];
190
190
  case 1:
191
191
  canBeTracked = _a.sent();
192
- if (!canBeTracked) {
193
- if (options.debug && options.enableLogging) {
194
- console.log('[Chord Analytics DEBUG]: User cannot be tracked, returning null');
195
- }
196
- return [2 /*return*/, null];
192
+ if (!!canBeTracked) return [3 /*break*/, 6];
193
+ if (options.debug && options.enableLogging) {
194
+ console.log('[Chord Analytics DEBUG]: User cannot be tracked, returning null');
197
195
  }
198
196
  _a.label = 2;
199
197
  case 2:
200
198
  _a.trys.push([2, 4, , 5]);
201
199
  return [4 /*yield*/, setupConsentManagement()];
202
- case 3: return [2 /*return*/, _a.sent()];
200
+ case 3:
201
+ _a.sent();
202
+ return [3 /*break*/, 5];
203
203
  case 4:
204
204
  error_2 = _a.sent();
205
205
  console.error('Error setting up consent management:', error_2);
206
+ return [3 /*break*/, 5];
207
+ case 5: return [2 /*return*/, null];
208
+ case 6:
209
+ _a.trys.push([6, 8, , 9]);
210
+ return [4 /*yield*/, setupConsentManagement()];
211
+ case 7: return [2 /*return*/, _a.sent()];
212
+ case 8:
213
+ error_3 = _a.sent();
214
+ console.error('Error setting up consent management:', error_3);
206
215
  return [2 /*return*/, null];
207
- case 5: return [2 /*return*/];
216
+ case 9: return [2 /*return*/];
208
217
  }
209
218
  });
210
219
  }); };
@@ -7,14 +7,17 @@ exports.shopifyConsentAdapter = void 0;
7
7
  var getApi = function () { var _a; return (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy; };
8
8
  /**
9
9
  * Returns whether the user can currently be tracked.
10
+ *
11
+ * Region is deliberately not checked: Shopify returns an empty region for
12
+ * visitors it hasn't geolocated (e.g. US visitors who never see a banner),
13
+ * even when analytics and marketing are both allowed. Opt-in regions already
14
+ * report both as not allowed until the visitor accepts.
10
15
  */
11
16
  var userCanBeTracked = function () {
12
17
  var api = getApi();
13
18
  if (!api)
14
19
  return false;
15
- return !!(api.getRegion() &&
16
- api.analyticsProcessingAllowed() &&
17
- api.marketingAllowed());
20
+ return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
18
21
  };
19
22
  /**
20
23
  * Returns the user's current consent configuration.
@@ -136,6 +136,14 @@ export const addCdpConsent = (options) => {
136
136
  if (options.debug && options.enableLogging) {
137
137
  console.log('[Chord Analytics DEBUG]: User cannot be tracked, returning null');
138
138
  }
139
+ // Still listen for consent changes, so a visitor who accepts after
140
+ // the timeout is picked up instead of being lost for the whole visit.
141
+ try {
142
+ yield setupConsentManagement();
143
+ }
144
+ catch (error) {
145
+ console.error('Error setting up consent management:', error);
146
+ }
139
147
  return null;
140
148
  }
141
149
  }
@@ -4,14 +4,17 @@
4
4
  const getApi = () => { var _a; return (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy; };
5
5
  /**
6
6
  * Returns whether the user can currently be tracked.
7
+ *
8
+ * Region is deliberately not checked: Shopify returns an empty region for
9
+ * visitors it hasn't geolocated (e.g. US visitors who never see a banner),
10
+ * even when analytics and marketing are both allowed. Opt-in regions already
11
+ * report both as not allowed until the visitor accepts.
7
12
  */
8
13
  const userCanBeTracked = () => {
9
14
  const api = getApi();
10
15
  if (!api)
11
16
  return false;
12
- return !!(api.getRegion() &&
13
- api.analyticsProcessingAllowed() &&
14
- api.marketingAllowed());
17
+ return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
15
18
  };
16
19
  /**
17
20
  * Returns the user's current consent configuration.
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.24.2",
4
+ "version": "1.24.3",
5
5
  "author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
6
6
  "repository": {
7
7
  "type": "git",