@blotoutio/providers-shop-gpt-sdk 1.31.2 → 1.31.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.
package/index.cjs.js CHANGED
@@ -473,6 +473,48 @@ new Set([
473
473
  'orderPlaced',
474
474
  ]);
475
475
 
476
+ const checkBotVisibility = ({ botVisibilityConditions, currentUrl, }) => {
477
+ const result = {
478
+ shouldHideBot: false,
479
+ };
480
+ if (!(botVisibilityConditions === null || botVisibilityConditions === void 0 ? void 0 : botVisibilityConditions.hideBot)) {
481
+ return result;
482
+ }
483
+ if (botVisibilityConditions.utmExclusion &&
484
+ botVisibilityConditions.utmExclusion.length > 0) {
485
+ const utmExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.utmExclusion, currentUrl);
486
+ if (utmExclusionResult.isExcluded) {
487
+ return {
488
+ shouldHideBot: true,
489
+ reason: 'UTM parameters matched exclusion criteria',
490
+ matchedParams: utmExclusionResult.matchedParams,
491
+ };
492
+ }
493
+ }
494
+ return result;
495
+ };
496
+ const checkURLSearchParamExclusion = (excludeParams, currentUrl) => {
497
+ const result = {
498
+ isExcluded: false,
499
+ matchedParams: [],
500
+ };
501
+ if (!excludeParams || excludeParams.length === 0) {
502
+ return result;
503
+ }
504
+ try {
505
+ const url = new URL(currentUrl);
506
+ const urlParams = new URLSearchParams(url.search);
507
+ const matchedParams = excludeParams.filter((param) => urlParams.has(param));
508
+ return {
509
+ isExcluded: matchedParams.length > 0,
510
+ matchedParams,
511
+ };
512
+ }
513
+ catch (error) {
514
+ return result;
515
+ }
516
+ };
517
+
476
518
  const packageName = 'shopGPT';
477
519
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
478
520
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1018,7 +1060,20 @@ const init = (params) => {
1018
1060
  error('Error in setting the sessionStorage for previewShopGPT');
1019
1061
  }
1020
1062
  }
1021
- const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1063
+ const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, botVisibilityConditions, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1064
+ let shouldHideBot = false;
1065
+ if (botVisibilityConditions) {
1066
+ const visibilityResult = checkBotVisibility({
1067
+ botVisibilityConditions,
1068
+ currentUrl: window.location.href,
1069
+ });
1070
+ if (visibilityResult.shouldHideBot) {
1071
+ logger.log(`ShopGPT disabled: ${visibilityResult.reason}${visibilityResult.matchedParams
1072
+ ? ` (${visibilityResult.matchedParams.join(', ')})`
1073
+ : ''}`);
1074
+ shouldHideBot = true;
1075
+ }
1076
+ }
1022
1077
  const experiment = createExperiment({
1023
1078
  name: getExperimentName(mode),
1024
1079
  userId: params.userId,
@@ -1027,7 +1082,7 @@ const init = (params) => {
1027
1082
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1028
1083
  : undefined,
1029
1084
  });
1030
- const shouldShowUI = enabled || experiment.isEnabled;
1085
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1031
1086
  if (experiment.name === 'preview' && shouldShowUI) {
1032
1087
  logger.log('Enabling UI in preview mode');
1033
1088
  }
@@ -11114,8 +11169,12 @@ class ShopGPT extends i$1 {
11114
11169
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11115
11170
  const isDesktop = window.innerWidth > 768;
11116
11171
  const wasModalOpen = isModalOpen(this.destination);
11117
- // If the url has `utm_source` open the popup when reloaded
11118
- if ((hasSource && isDesktop) || wasModalOpen) {
11172
+ // If user came from ShopGPT product recommendation, don't open modal
11173
+ if (hasSource) {
11174
+ return;
11175
+ }
11176
+ // For non-product pages, check session storage to restore modal state
11177
+ if (wasModalOpen && isDesktop) {
11119
11178
  this.modalState = 'open';
11120
11179
  setUserInteracted(this.destination);
11121
11180
  }
package/index.js CHANGED
@@ -474,6 +474,48 @@ var ProvidersShopGptSdk = (function () {
474
474
  'orderPlaced',
475
475
  ]);
476
476
 
477
+ const checkBotVisibility = ({ botVisibilityConditions, currentUrl, }) => {
478
+ const result = {
479
+ shouldHideBot: false,
480
+ };
481
+ if (!(botVisibilityConditions === null || botVisibilityConditions === void 0 ? void 0 : botVisibilityConditions.hideBot)) {
482
+ return result;
483
+ }
484
+ if (botVisibilityConditions.utmExclusion &&
485
+ botVisibilityConditions.utmExclusion.length > 0) {
486
+ const utmExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.utmExclusion, currentUrl);
487
+ if (utmExclusionResult.isExcluded) {
488
+ return {
489
+ shouldHideBot: true,
490
+ reason: 'UTM parameters matched exclusion criteria',
491
+ matchedParams: utmExclusionResult.matchedParams,
492
+ };
493
+ }
494
+ }
495
+ return result;
496
+ };
497
+ const checkURLSearchParamExclusion = (excludeParams, currentUrl) => {
498
+ const result = {
499
+ isExcluded: false,
500
+ matchedParams: [],
501
+ };
502
+ if (!excludeParams || excludeParams.length === 0) {
503
+ return result;
504
+ }
505
+ try {
506
+ const url = new URL(currentUrl);
507
+ const urlParams = new URLSearchParams(url.search);
508
+ const matchedParams = excludeParams.filter((param) => urlParams.has(param));
509
+ return {
510
+ isExcluded: matchedParams.length > 0,
511
+ matchedParams,
512
+ };
513
+ }
514
+ catch (error) {
515
+ return result;
516
+ }
517
+ };
518
+
477
519
  const packageName = 'shopGPT';
478
520
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
479
521
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1019,7 +1061,20 @@ var ProvidersShopGptSdk = (function () {
1019
1061
  error('Error in setting the sessionStorage for previewShopGPT');
1020
1062
  }
1021
1063
  }
1022
- const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1064
+ const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, botVisibilityConditions, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1065
+ let shouldHideBot = false;
1066
+ if (botVisibilityConditions) {
1067
+ const visibilityResult = checkBotVisibility({
1068
+ botVisibilityConditions,
1069
+ currentUrl: window.location.href,
1070
+ });
1071
+ if (visibilityResult.shouldHideBot) {
1072
+ logger.log(`ShopGPT disabled: ${visibilityResult.reason}${visibilityResult.matchedParams
1073
+ ? ` (${visibilityResult.matchedParams.join(', ')})`
1074
+ : ''}`);
1075
+ shouldHideBot = true;
1076
+ }
1077
+ }
1023
1078
  const experiment = createExperiment({
1024
1079
  name: getExperimentName(mode),
1025
1080
  userId: params.userId,
@@ -1028,7 +1083,7 @@ var ProvidersShopGptSdk = (function () {
1028
1083
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1029
1084
  : undefined,
1030
1085
  });
1031
- const shouldShowUI = enabled || experiment.isEnabled;
1086
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1032
1087
  if (experiment.name === 'preview' && shouldShowUI) {
1033
1088
  logger.log('Enabling UI in preview mode');
1034
1089
  }
@@ -11115,8 +11170,12 @@ ${this.comment ? this.comment : E}</textarea
11115
11170
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11116
11171
  const isDesktop = window.innerWidth > 768;
11117
11172
  const wasModalOpen = isModalOpen(this.destination);
11118
- // If the url has `utm_source` open the popup when reloaded
11119
- if ((hasSource && isDesktop) || wasModalOpen) {
11173
+ // If user came from ShopGPT product recommendation, don't open modal
11174
+ if (hasSource) {
11175
+ return;
11176
+ }
11177
+ // For non-product pages, check session storage to restore modal state
11178
+ if (wasModalOpen && isDesktop) {
11120
11179
  this.modalState = 'open';
11121
11180
  setUserInteracted(this.destination);
11122
11181
  }
package/index.mjs CHANGED
@@ -471,6 +471,48 @@ new Set([
471
471
  'orderPlaced',
472
472
  ]);
473
473
 
474
+ const checkBotVisibility = ({ botVisibilityConditions, currentUrl, }) => {
475
+ const result = {
476
+ shouldHideBot: false,
477
+ };
478
+ if (!(botVisibilityConditions === null || botVisibilityConditions === void 0 ? void 0 : botVisibilityConditions.hideBot)) {
479
+ return result;
480
+ }
481
+ if (botVisibilityConditions.utmExclusion &&
482
+ botVisibilityConditions.utmExclusion.length > 0) {
483
+ const utmExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.utmExclusion, currentUrl);
484
+ if (utmExclusionResult.isExcluded) {
485
+ return {
486
+ shouldHideBot: true,
487
+ reason: 'UTM parameters matched exclusion criteria',
488
+ matchedParams: utmExclusionResult.matchedParams,
489
+ };
490
+ }
491
+ }
492
+ return result;
493
+ };
494
+ const checkURLSearchParamExclusion = (excludeParams, currentUrl) => {
495
+ const result = {
496
+ isExcluded: false,
497
+ matchedParams: [],
498
+ };
499
+ if (!excludeParams || excludeParams.length === 0) {
500
+ return result;
501
+ }
502
+ try {
503
+ const url = new URL(currentUrl);
504
+ const urlParams = new URLSearchParams(url.search);
505
+ const matchedParams = excludeParams.filter((param) => urlParams.has(param));
506
+ return {
507
+ isExcluded: matchedParams.length > 0,
508
+ matchedParams,
509
+ };
510
+ }
511
+ catch (error) {
512
+ return result;
513
+ }
514
+ };
515
+
474
516
  const packageName = 'shopGPT';
475
517
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
476
518
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1016,7 +1058,20 @@ const init = (params) => {
1016
1058
  error('Error in setting the sessionStorage for previewShopGPT');
1017
1059
  }
1018
1060
  }
1019
- const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1061
+ const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, supportPrompts, searchSuggestions, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, metafieldDisplayName, showClassicChatbot, chatbotIconType, botVisibilityConditions, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
1062
+ let shouldHideBot = false;
1063
+ if (botVisibilityConditions) {
1064
+ const visibilityResult = checkBotVisibility({
1065
+ botVisibilityConditions,
1066
+ currentUrl: window.location.href,
1067
+ });
1068
+ if (visibilityResult.shouldHideBot) {
1069
+ logger.log(`ShopGPT disabled: ${visibilityResult.reason}${visibilityResult.matchedParams
1070
+ ? ` (${visibilityResult.matchedParams.join(', ')})`
1071
+ : ''}`);
1072
+ shouldHideBot = true;
1073
+ }
1074
+ }
1020
1075
  const experiment = createExperiment({
1021
1076
  name: getExperimentName(mode),
1022
1077
  userId: params.userId,
@@ -1025,7 +1080,7 @@ const init = (params) => {
1025
1080
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1026
1081
  : undefined,
1027
1082
  });
1028
- const shouldShowUI = enabled || experiment.isEnabled;
1083
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1029
1084
  if (experiment.name === 'preview' && shouldShowUI) {
1030
1085
  logger.log('Enabling UI in preview mode');
1031
1086
  }
@@ -11112,8 +11167,12 @@ class ShopGPT extends i$1 {
11112
11167
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11113
11168
  const isDesktop = window.innerWidth > 768;
11114
11169
  const wasModalOpen = isModalOpen(this.destination);
11115
- // If the url has `utm_source` open the popup when reloaded
11116
- if ((hasSource && isDesktop) || wasModalOpen) {
11170
+ // If user came from ShopGPT product recommendation, don't open modal
11171
+ if (hasSource) {
11172
+ return;
11173
+ }
11174
+ // For non-product pages, check session storage to restore modal state
11175
+ if (wasModalOpen && isDesktop) {
11117
11176
  this.modalState = 'open';
11118
11177
  setUserInteracted(this.destination);
11119
11178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-shop-gpt-sdk",
3
- "version": "1.31.2",
3
+ "version": "1.31.3",
4
4
  "description": "Shop GPT SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",