@blotoutio/providers-shop-gpt-sdk 1.31.2 → 1.31.4

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,50 @@ 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.urlSearchParamExclusion &&
484
+ botVisibilityConditions.urlSearchParamExclusion.length > 0) {
485
+ const urlSearchParamExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.urlSearchParamExclusion, currentUrl);
486
+ if (urlSearchParamExclusionResult.isExcluded) {
487
+ return {
488
+ shouldHideBot: true,
489
+ reason: 'URL search parameters matched exclusion criteria',
490
+ matchedParams: urlSearchParamExclusionResult.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) => {
508
+ return urlParams.has(param);
509
+ });
510
+ return {
511
+ isExcluded: matchedParams.length > 0,
512
+ matchedParams,
513
+ };
514
+ }
515
+ catch (error) {
516
+ return result;
517
+ }
518
+ };
519
+
476
520
  const packageName = 'shopGPT';
477
521
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
478
522
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1018,7 +1062,20 @@ const init = (params) => {
1018
1062
  error('Error in setting the sessionStorage for previewShopGPT');
1019
1063
  }
1020
1064
  }
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 : {};
1065
+ 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 : {};
1066
+ let shouldHideBot = false;
1067
+ if (botVisibilityConditions) {
1068
+ const visibilityResult = checkBotVisibility({
1069
+ botVisibilityConditions,
1070
+ currentUrl: window.location.href,
1071
+ });
1072
+ if (visibilityResult.shouldHideBot) {
1073
+ logger.log(`ShopGPT disabled: ${visibilityResult.reason}${visibilityResult.matchedParams
1074
+ ? ` (${visibilityResult.matchedParams.join(', ')})`
1075
+ : ''}`);
1076
+ shouldHideBot = true;
1077
+ }
1078
+ }
1022
1079
  const experiment = createExperiment({
1023
1080
  name: getExperimentName(mode),
1024
1081
  userId: params.userId,
@@ -1027,7 +1084,7 @@ const init = (params) => {
1027
1084
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1028
1085
  : undefined,
1029
1086
  });
1030
- const shouldShowUI = enabled || experiment.isEnabled;
1087
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1031
1088
  if (experiment.name === 'preview' && shouldShowUI) {
1032
1089
  logger.log('Enabling UI in preview mode');
1033
1090
  }
@@ -11114,8 +11171,12 @@ class ShopGPT extends i$1 {
11114
11171
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11115
11172
  const isDesktop = window.innerWidth > 768;
11116
11173
  const wasModalOpen = isModalOpen(this.destination);
11117
- // If the url has `utm_source` open the popup when reloaded
11118
- if ((hasSource && isDesktop) || wasModalOpen) {
11174
+ // If user came from ShopGPT product recommendation, don't open modal
11175
+ if (hasSource) {
11176
+ return;
11177
+ }
11178
+ // For non-product pages, check session storage to restore modal state
11179
+ if (wasModalOpen && isDesktop) {
11119
11180
  this.modalState = 'open';
11120
11181
  setUserInteracted(this.destination);
11121
11182
  }
package/index.js CHANGED
@@ -474,6 +474,50 @@ 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.urlSearchParamExclusion &&
485
+ botVisibilityConditions.urlSearchParamExclusion.length > 0) {
486
+ const urlSearchParamExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.urlSearchParamExclusion, currentUrl);
487
+ if (urlSearchParamExclusionResult.isExcluded) {
488
+ return {
489
+ shouldHideBot: true,
490
+ reason: 'URL search parameters matched exclusion criteria',
491
+ matchedParams: urlSearchParamExclusionResult.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) => {
509
+ return urlParams.has(param);
510
+ });
511
+ return {
512
+ isExcluded: matchedParams.length > 0,
513
+ matchedParams,
514
+ };
515
+ }
516
+ catch (error) {
517
+ return result;
518
+ }
519
+ };
520
+
477
521
  const packageName = 'shopGPT';
478
522
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
479
523
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1019,7 +1063,20 @@ var ProvidersShopGptSdk = (function () {
1019
1063
  error('Error in setting the sessionStorage for previewShopGPT');
1020
1064
  }
1021
1065
  }
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 : {};
1066
+ 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 : {};
1067
+ let shouldHideBot = false;
1068
+ if (botVisibilityConditions) {
1069
+ const visibilityResult = checkBotVisibility({
1070
+ botVisibilityConditions,
1071
+ currentUrl: window.location.href,
1072
+ });
1073
+ if (visibilityResult.shouldHideBot) {
1074
+ logger.log(`ShopGPT disabled: ${visibilityResult.reason}${visibilityResult.matchedParams
1075
+ ? ` (${visibilityResult.matchedParams.join(', ')})`
1076
+ : ''}`);
1077
+ shouldHideBot = true;
1078
+ }
1079
+ }
1023
1080
  const experiment = createExperiment({
1024
1081
  name: getExperimentName(mode),
1025
1082
  userId: params.userId,
@@ -1028,7 +1085,7 @@ var ProvidersShopGptSdk = (function () {
1028
1085
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1029
1086
  : undefined,
1030
1087
  });
1031
- const shouldShowUI = enabled || experiment.isEnabled;
1088
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1032
1089
  if (experiment.name === 'preview' && shouldShowUI) {
1033
1090
  logger.log('Enabling UI in preview mode');
1034
1091
  }
@@ -11115,8 +11172,12 @@ ${this.comment ? this.comment : E}</textarea
11115
11172
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11116
11173
  const isDesktop = window.innerWidth > 768;
11117
11174
  const wasModalOpen = isModalOpen(this.destination);
11118
- // If the url has `utm_source` open the popup when reloaded
11119
- if ((hasSource && isDesktop) || wasModalOpen) {
11175
+ // If user came from ShopGPT product recommendation, don't open modal
11176
+ if (hasSource) {
11177
+ return;
11178
+ }
11179
+ // For non-product pages, check session storage to restore modal state
11180
+ if (wasModalOpen && isDesktop) {
11120
11181
  this.modalState = 'open';
11121
11182
  setUserInteracted(this.destination);
11122
11183
  }
package/index.mjs CHANGED
@@ -471,6 +471,50 @@ 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.urlSearchParamExclusion &&
482
+ botVisibilityConditions.urlSearchParamExclusion.length > 0) {
483
+ const urlSearchParamExclusionResult = checkURLSearchParamExclusion(botVisibilityConditions.urlSearchParamExclusion, currentUrl);
484
+ if (urlSearchParamExclusionResult.isExcluded) {
485
+ return {
486
+ shouldHideBot: true,
487
+ reason: 'URL search parameters matched exclusion criteria',
488
+ matchedParams: urlSearchParamExclusionResult.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) => {
506
+ return urlParams.has(param);
507
+ });
508
+ return {
509
+ isExcluded: matchedParams.length > 0,
510
+ matchedParams,
511
+ };
512
+ }
513
+ catch (error) {
514
+ return result;
515
+ }
516
+ };
517
+
474
518
  const packageName = 'shopGPT';
475
519
  const DEFAULT_MAX_THREAD_AGE = 14; // in days
476
520
  const DEFAULT_NUDGE_TIMEOUT = 10; // in seconds
@@ -1016,7 +1060,20 @@ const init = (params) => {
1016
1060
  error('Error in setting the sessionStorage for previewShopGPT');
1017
1061
  }
1018
1062
  }
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 : {};
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
+ }
1020
1077
  const experiment = createExperiment({
1021
1078
  name: getExperimentName(mode),
1022
1079
  userId: params.userId,
@@ -1025,7 +1082,7 @@ const init = (params) => {
1025
1082
  ? (_d = params.manifest.variables) === null || _d === void 0 ? void 0 : _d.rolloutPercentage
1026
1083
  : undefined,
1027
1084
  });
1028
- const shouldShowUI = enabled || experiment.isEnabled;
1085
+ const shouldShowUI = (enabled || experiment.isEnabled) && !shouldHideBot;
1029
1086
  if (experiment.name === 'preview' && shouldShowUI) {
1030
1087
  logger.log('Enabling UI in preview mode');
1031
1088
  }
@@ -11112,8 +11169,12 @@ class ShopGPT extends i$1 {
11112
11169
  const hasSource = searchParams.get('utm_source') === 'shopgpt';
11113
11170
  const isDesktop = window.innerWidth > 768;
11114
11171
  const wasModalOpen = isModalOpen(this.destination);
11115
- // If the url has `utm_source` open the popup when reloaded
11116
- 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) {
11117
11178
  this.modalState = 'open';
11118
11179
  setUserInteracted(this.destination);
11119
11180
  }
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.4",
4
4
  "description": "Shop GPT SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",