@ada-support/embed2 1.7.8 → 1.7.9

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.
@@ -1 +1,14 @@
1
+ /** The logic below determines whether or not the chat button is visible if the rollout is not 100%
2
+ * GROUP A - DOES NOT SEE CHAT BUTTON
3
+ * GROUP B - SEE'S CHAT BUTTON
4
+ *
5
+ * First we check if the rollout is either 100% or 0%. In either of these cases we do not need to check the probability score to determine their grouping.
6
+ * - If the rollout is 100% we put the user in group B and they see the button.
7
+ * - If the rollout is 0% we put the user in group A and they do not see the button.
8
+ * - If the rollout is between 0% and 100% we need to check the probability score to determine their grouping and store the result.
9
+ *
10
+ * - If the user has not been put in a group yet we need to put them in a group and store the result.
11
+ * - If the user has already been put in a group and the rollout has not changed we do not need to move them.
12
+ * - If the user has already been put in a group and the rollout has changed we need to check if they should be moved to the other group and store the result.
13
+ */
1
14
  export declare function checkRollout(rollout: number, handle: string): boolean;
@@ -13260,7 +13260,7 @@ const client = new error_tracker_BrowserClient({
13260
13260
  return event;
13261
13261
  },
13262
13262
  environment: "production",
13263
- release: "1.7.8-eceb93f",
13263
+ release: "1.7.9-9921e9b",
13264
13264
  sampleRate: 0.25,
13265
13265
  autoSessionTracking: false,
13266
13266
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -13832,7 +13832,7 @@ function getEmbedURL(_ref) {
13832
13832
  } else {
13833
13833
  host = `http://${handle}.localhost:9001`;
13834
13834
  }
13835
- return `${host}/embed/${frameName}/${"eceb93f"}/index.html`;
13835
+ return `${host}/embed/${frameName}/${"9921e9b"}/index.html`;
13836
13836
  }
13837
13837
  function constructQueryString(query) {
13838
13838
  return Object.keys(query).map(key => {
@@ -14993,9 +14993,9 @@ async function log(message, extra, options) {
14993
14993
  service: "embed",
14994
14994
  env: "production",
14995
14995
  embedVersion: 2,
14996
- version: "1.7.8",
14996
+ version: "1.7.9",
14997
14997
  isNpm: true,
14998
- commitHash: "eceb93f"
14998
+ commitHash: "9921e9b"
14999
14999
  }))
15000
15000
  });
15001
15001
  }
@@ -15221,6 +15221,7 @@ function unbindLocationChangeOverrides() {
15221
15221
  function rollout_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15222
15222
  function rollout_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? rollout_ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : rollout_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15223
15223
 
15224
+
15224
15225
  function storeRollout(handle, group, lastProb) {
15225
15226
  dist/* adaLocalStorage.setFnItem */.wG.setFnItem("rolloutGroup", rollout_objectSpread(rollout_objectSpread({}, dist/* adaLocalStorage.getFnItem */.wG.getFnItem("rolloutGroup")), {}, {
15226
15227
  [handle]: group
@@ -15245,64 +15246,71 @@ function readRollout(handle) {
15245
15246
  rollout.lastProb = (dist/* adaLocalStorage.getFnItem */.wG.getFnItem("rolloutLastValue") || {})[handle] || null;
15246
15247
  return rollout;
15247
15248
  }
15249
+
15250
+ /** The logic below determines whether or not the chat button is visible if the rollout is not 100%
15251
+ * GROUP A - DOES NOT SEE CHAT BUTTON
15252
+ * GROUP B - SEE'S CHAT BUTTON
15253
+ *
15254
+ * First we check if the rollout is either 100% or 0%. In either of these cases we do not need to check the probability score to determine their grouping.
15255
+ * - If the rollout is 100% we put the user in group B and they see the button.
15256
+ * - If the rollout is 0% we put the user in group A and they do not see the button.
15257
+ * - If the rollout is between 0% and 100% we need to check the probability score to determine their grouping and store the result.
15258
+ *
15259
+ * - If the user has not been put in a group yet we need to put them in a group and store the result.
15260
+ * - If the user has already been put in a group and the rollout has not changed we do not need to move them.
15261
+ * - If the user has already been put in a group and the rollout has changed we need to check if they should be moved to the other group and store the result.
15262
+ */
15248
15263
  function checkRollout(rollout, handle) {
15249
- if (rollout >= 0 && rollout <= 1) {
15250
- // We should first check the storage to see if this user is already grouped
15251
- const rg = readRollout(handle);
15252
- const rand = Math.random();
15253
- if (rg.group === null || rg.lastProb === 0) {
15254
- // No group assigned yet
15255
- // A is control (does not see button)
15256
- // B is variant (sees chat button)
15257
- const roll = rand <= rollout;
15258
- const group = roll ? "B" : "A";
15259
- storeRollout(handle, group, rollout);
15260
- return roll;
15261
- }
15262
- if (rg.group === "A" || rg.group === "B") {
15263
- // Check to see if the remote rollout probability has changed from the last time it was set
15264
- if (rg.lastProb !== null && rg.lastProb !== rollout) {
15265
- // Probability has changed since the last time it was set
15266
- // Use Gordon's function to determine who should move where
15267
- if (rollout === 0) {
15268
- // Move all B's to group A
15269
- storeRollout(handle, "A", 0);
15270
- return false;
15271
- }
15272
- if (rollout === 1) {
15273
- // Move all A's to group B
15274
- storeRollout(handle, "B", 1);
15275
- return true;
15276
- }
15277
- if (rollout < rg.lastProb) {
15278
- // DOWNGRADE CASE
15279
- // If you are in group B you now could be moved to group A
15280
- if (rg.group === "B") {
15281
- const adjustedProb = 1 - rollout / rg.lastProb;
15282
- const shouldMove = rand <= adjustedProb;
15283
- const group = shouldMove ? "B" : "A";
15284
- storeRollout(handle, group, rollout);
15285
- return shouldMove;
15286
- }
15287
- } else if (rollout > rg.lastProb) {
15288
- // UPGRADE CASE
15289
- // If you are in group A, you now have an opportunity to become group B
15290
- if (rg.group === "A") {
15291
- const adjustedProb = 1 - rg.lastProb / rollout;
15292
- const shouldMove = rand <= adjustedProb;
15293
- const group = shouldMove ? "B" : "A";
15294
- storeRollout(handle, group, rollout);
15295
- return shouldMove;
15296
- }
15297
- }
15298
- } else {
15299
- // Probability is the same as before.
15300
- return rg.group === "B";
15301
- }
15302
- }
15264
+ // Get current rollout percentage in browser storage
15265
+ const userRolloutGroup = readRollout(handle);
15266
+
15267
+ // If somehow the rollout doesn't fall within the 0% to 100% range - just show the button
15268
+ if (rollout < 0 || rollout > 1) {
15269
+ warn("Rollout value must be between 0 and 1 - defaulting to 1");
15270
+ return true;
15271
+ }
15272
+
15273
+ // If rollout is 1 or 0 - just check if we should show the button or not and store the result
15274
+ // This also acts as a reset if someone accidentally gets put in group A but the rollout changed to
15275
+ // 100% - they will now be put in group B
15276
+ if (rollout === 1 || rollout === 0) {
15277
+ const group = rollout ? "B" : "A";
15278
+ storeRollout(handle, group, rollout);
15279
+ return group === "B";
15280
+ }
15281
+
15282
+ // If the user has already been put in a group and it hasn't changed - don't move them
15283
+ if (rollout === userRolloutGroup.lastProb) {
15284
+ return userRolloutGroup.group === "B";
15285
+ }
15286
+
15287
+ // Generate a random number to test against the probability score
15288
+ const rand = Math.random();
15289
+
15290
+ // If the user has not been put in a group yet - test against the probability score to determine their group and assign it to them
15291
+ if (userRolloutGroup.group === null || userRolloutGroup.lastProb === 0) {
15292
+ const roll = rand <= rollout;
15293
+ const group = roll ? "B" : "A";
15294
+ storeRollout(handle, group, rollout);
15295
+ return roll;
15296
+ }
15297
+
15298
+ // If we got here the rollout value has changed and is either higher or lower than the previous value
15299
+ if (userRolloutGroup.lastProb !== null && rollout > 0) {
15300
+ // If the rollout is higher than previous we want to test against the probability score to see if they get upgraded to group B
15301
+ // If the rollout is lower than previous we want to test against the probability score to see if they get downgraded to group A
15302
+ const adjustedProb = rollout > userRolloutGroup.lastProb ? 1 - userRolloutGroup.lastProb / rollout // This is the math to see if the user gets upgraded to group B
15303
+ : 1 - rollout / userRolloutGroup.lastProb; // This is the math to see if the user gets downgraded to group A
15304
+
15305
+ // If the random number is less than or equal to the adjusted probability score - we will upgrade the user to group B, otherwise they will go to group A
15306
+ const shouldBeVisible = rand <= adjustedProb;
15307
+ const group = shouldBeVisible ? "B" : "A";
15308
+ storeRollout(handle, group, rollout);
15309
+ return shouldBeVisible;
15303
15310
  }
15304
15311
 
15305
- // Default to being on just in case of unforeseen failure cases
15312
+ // If all else fails show the button
15313
+ warn("Unable to detemrine rollout group - defaulting to showing chat button");
15306
15314
  return true;
15307
15315
  }
15308
15316
  ;// CONCATENATED MODULE: ./src/client/helpers/web-notifications/web-notification-events.ts
@@ -16016,7 +16024,7 @@ class ChatFrame extends d {
16016
16024
  const hostPageUrlParams = new URL(window.location.href).searchParams;
16017
16025
  const smsToken = hostPageUrlParams.get("adaSMSToken");
16018
16026
  const queryParams = {
16019
- embedVersion: "eceb93f".slice(0, 7),
16027
+ embedVersion: "9921e9b".slice(0, 7),
16020
16028
  greeting,
16021
16029
  language,
16022
16030
  skipGreeting,
@@ -17575,7 +17583,8 @@ class Container extends d {
17575
17583
  return;
17576
17584
  }
17577
17585
  const primaryBotClient = new Client(clientResponse.client);
17578
- const shouldHideEmbedButton = !checkRollout(rolloutOverride || primaryBotClient.rollout, primaryBotClient.handle);
17586
+ const rolloutPercentage = rolloutOverride !== undefined ? rolloutOverride : primaryBotClient.rollout;
17587
+ const shouldHideEmbedButton = !checkRollout(rolloutPercentage, primaryBotClient.handle);
17579
17588
 
17580
17589
  // if there is a bot override handle in the URL, we should ignore the primary rollout which determines whether any embed button is shown
17581
17590
  if (shouldHideEmbedButton && !getBotOverrideHandleFromWebpageURL()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",