@economist/web-apple-pay 1.9.3 → 1.9.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/dist/index.js CHANGED
@@ -1353,7 +1353,7 @@ var track = (action, extra) => {
1353
1353
  ...extra
1354
1354
  });
1355
1355
  };
1356
- var trackApplePayExperimentExposure = (variant) => {
1356
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
1357
1357
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1358
1358
  if (!isActiveVariant) {
1359
1359
  return;
@@ -1369,7 +1369,8 @@ var trackApplePayExperimentExposure = (variant) => {
1369
1369
  emitTedlEvent({
1370
1370
  name: "$exposure",
1371
1371
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
1372
- variant
1372
+ variant,
1373
+ ...experimentKey ? { experiment_key: experimentKey } : {}
1373
1374
  });
1374
1375
  };
1375
1376
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -1995,6 +1996,13 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1995
1996
  return [...zoneCountries];
1996
1997
  };
1997
1998
 
1999
+ // src/utils/getExperimentKeyFromNextData.ts
2000
+ var getExperimentKeyFromNextData = (flagKey) => {
2001
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
2002
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
2003
+ return typeof experimentKey === "string" ? experimentKey : void 0;
2004
+ };
2005
+
1998
2006
  // src/apple-pay-button.ts
1999
2007
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
2000
2008
  var TOTAL_LABEL = "The Economist";
@@ -2041,7 +2049,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2041
2049
  APPLE_PAY_EXPRESS_EXPERIMENT_KEY
2042
2050
  );
2043
2051
  if (experimentValue) {
2044
- trackApplePayExperimentExposure(experimentValue);
2052
+ trackApplePayExperimentExposure(
2053
+ experimentValue,
2054
+ getExperimentKeyFromNextData(APPLE_PAY_EXPRESS_EXPERIMENT_KEY)
2055
+ );
2045
2056
  }
2046
2057
  const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2047
2058
  const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
@@ -1342,7 +1342,7 @@ var track = (action, extra) => {
1342
1342
  ...extra
1343
1343
  });
1344
1344
  };
1345
- var trackApplePayExperimentExposure = (variant) => {
1345
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
1346
1346
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1347
1347
  if (!isActiveVariant) {
1348
1348
  return;
@@ -1358,7 +1358,8 @@ var trackApplePayExperimentExposure = (variant) => {
1358
1358
  emitTedlEvent({
1359
1359
  name: "$exposure",
1360
1360
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
1361
- variant
1361
+ variant,
1362
+ ...experimentKey ? { experiment_key: experimentKey } : {}
1362
1363
  });
1363
1364
  };
1364
1365
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -1984,6 +1985,13 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1984
1985
  return [...zoneCountries];
1985
1986
  };
1986
1987
 
1988
+ // src/utils/getExperimentKeyFromNextData.ts
1989
+ var getExperimentKeyFromNextData = (flagKey) => {
1990
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
1991
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
1992
+ return typeof experimentKey === "string" ? experimentKey : void 0;
1993
+ };
1994
+
1987
1995
  // src/apple-pay-button.ts
1988
1996
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1989
1997
  var TOTAL_LABEL = "The Economist";
@@ -2030,7 +2038,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2030
2038
  APPLE_PAY_EXPRESS_EXPERIMENT_KEY
2031
2039
  );
2032
2040
  if (experimentValue) {
2033
- trackApplePayExperimentExposure(experimentValue);
2041
+ trackApplePayExperimentExposure(
2042
+ experimentValue,
2043
+ getExperimentKeyFromNextData(APPLE_PAY_EXPRESS_EXPERIMENT_KEY)
2044
+ );
2034
2045
  }
2035
2046
  const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2036
2047
  const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
@@ -1350,7 +1350,7 @@ var track = (action, extra) => {
1350
1350
  ...extra
1351
1351
  });
1352
1352
  };
1353
- var trackApplePayExperimentExposure = (variant) => {
1353
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
1354
1354
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1355
1355
  if (!isActiveVariant) {
1356
1356
  return;
@@ -1366,7 +1366,8 @@ var trackApplePayExperimentExposure = (variant) => {
1366
1366
  emitTedlEvent({
1367
1367
  name: "$exposure",
1368
1368
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
1369
- variant
1369
+ variant,
1370
+ ...experimentKey ? { experiment_key: experimentKey } : {}
1370
1371
  });
1371
1372
  };
1372
1373
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -1992,6 +1993,13 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1992
1993
  return [...zoneCountries];
1993
1994
  };
1994
1995
 
1996
+ // src/utils/getExperimentKeyFromNextData.ts
1997
+ var getExperimentKeyFromNextData = (flagKey) => {
1998
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
1999
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
2000
+ return typeof experimentKey === "string" ? experimentKey : void 0;
2001
+ };
2002
+
1995
2003
  // src/apple-pay-button.ts
1996
2004
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1997
2005
  var TOTAL_LABEL = "The Economist";
@@ -2038,7 +2046,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2038
2046
  APPLE_PAY_EXPRESS_EXPERIMENT_KEY
2039
2047
  );
2040
2048
  if (experimentValue) {
2041
- trackApplePayExperimentExposure(experimentValue);
2049
+ trackApplePayExperimentExposure(
2050
+ experimentValue,
2051
+ getExperimentKeyFromNextData(APPLE_PAY_EXPRESS_EXPERIMENT_KEY)
2052
+ );
2042
2053
  }
2043
2054
  const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2044
2055
  const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
@@ -1342,7 +1342,7 @@ var track = (action, extra) => {
1342
1342
  ...extra
1343
1343
  });
1344
1344
  };
1345
- var trackApplePayExperimentExposure = (variant) => {
1345
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
1346
1346
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1347
1347
  if (!isActiveVariant) {
1348
1348
  return;
@@ -1358,7 +1358,8 @@ var trackApplePayExperimentExposure = (variant) => {
1358
1358
  emitTedlEvent({
1359
1359
  name: "$exposure",
1360
1360
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
1361
- variant
1361
+ variant,
1362
+ ...experimentKey ? { experiment_key: experimentKey } : {}
1362
1363
  });
1363
1364
  };
1364
1365
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -1984,6 +1985,13 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1984
1985
  return [...zoneCountries];
1985
1986
  };
1986
1987
 
1988
+ // src/utils/getExperimentKeyFromNextData.ts
1989
+ var getExperimentKeyFromNextData = (flagKey) => {
1990
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
1991
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
1992
+ return typeof experimentKey === "string" ? experimentKey : void 0;
1993
+ };
1994
+
1987
1995
  // src/apple-pay-button.ts
1988
1996
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1989
1997
  var TOTAL_LABEL = "The Economist";
@@ -2030,7 +2038,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2030
2038
  APPLE_PAY_EXPRESS_EXPERIMENT_KEY
2031
2039
  );
2032
2040
  if (experimentValue) {
2033
- trackApplePayExperimentExposure(experimentValue);
2041
+ trackApplePayExperimentExposure(
2042
+ experimentValue,
2043
+ getExperimentKeyFromNextData(APPLE_PAY_EXPRESS_EXPERIMENT_KEY)
2044
+ );
2034
2045
  }
2035
2046
  const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2036
2047
  const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
package/dist/src/index.js CHANGED
@@ -1353,7 +1353,7 @@ var track = (action, extra) => {
1353
1353
  ...extra
1354
1354
  });
1355
1355
  };
1356
- var trackApplePayExperimentExposure = (variant) => {
1356
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
1357
1357
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
1358
1358
  if (!isActiveVariant) {
1359
1359
  return;
@@ -1369,7 +1369,8 @@ var trackApplePayExperimentExposure = (variant) => {
1369
1369
  emitTedlEvent({
1370
1370
  name: "$exposure",
1371
1371
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
1372
- variant
1372
+ variant,
1373
+ ...experimentKey ? { experiment_key: experimentKey } : {}
1373
1374
  });
1374
1375
  };
1375
1376
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -1995,6 +1996,13 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1995
1996
  return [...zoneCountries];
1996
1997
  };
1997
1998
 
1999
+ // src/utils/getExperimentKeyFromNextData.ts
2000
+ var getExperimentKeyFromNextData = (flagKey) => {
2001
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
2002
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
2003
+ return typeof experimentKey === "string" ? experimentKey : void 0;
2004
+ };
2005
+
1998
2006
  // src/apple-pay-button.ts
1999
2007
  var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
2000
2008
  var TOTAL_LABEL = "The Economist";
@@ -2041,7 +2049,10 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2041
2049
  APPLE_PAY_EXPRESS_EXPERIMENT_KEY
2042
2050
  );
2043
2051
  if (experimentValue) {
2044
- trackApplePayExperimentExposure(experimentValue);
2052
+ trackApplePayExperimentExposure(
2053
+ experimentValue,
2054
+ getExperimentKeyFromNextData(APPLE_PAY_EXPRESS_EXPERIMENT_KEY)
2055
+ );
2045
2056
  }
2046
2057
  const isTreatment = experimentValue === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
2047
2058
  const hasUrlParamFlag = new URLSearchParams(window.location.search).has(
@@ -52,9 +52,10 @@ export type ImpressionMetadata = {
52
52
  *
53
53
  * Fired when createIfEnabled evaluates an assigned variant (control or
54
54
  * treatment). Deduped per pathname + variant so repeated banner renders on
55
- * the same page do not over-count.
55
+ * the same page do not over-count. Includes experiment_key from Engagement
56
+ * SSR (__NEXT_DATA__) when present for Feature Experiment run attribution.
56
57
  */
57
- export declare const trackApplePayExperimentExposure: (variant: string) => void;
58
+ export declare const trackApplePayExperimentExposure: (variant: string, experimentKey?: string) => void;
58
59
  /** Wallet button displayed — emits all 5 required analytics dimensions. */
59
60
  export declare const trackExpressWalletImpression: (skuId: string, { entryPoint, country }: ImpressionMetadata) => void;
60
61
  /** Wallet button clicked */
@@ -42,7 +42,7 @@ var track = (action, extra) => {
42
42
  ...extra
43
43
  });
44
44
  };
45
- var trackApplePayExperimentExposure = (variant) => {
45
+ var trackApplePayExperimentExposure = (variant, experimentKey) => {
46
46
  const isActiveVariant = variant === APPLE_PAY_EXPRESS_VARIANTS.CONTROL || variant === APPLE_PAY_EXPRESS_VARIANTS.TREATMENT;
47
47
  if (!isActiveVariant) {
48
48
  return;
@@ -58,7 +58,8 @@ var trackApplePayExperimentExposure = (variant) => {
58
58
  emitTedlEvent({
59
59
  name: "$exposure",
60
60
  flag_key: APPLE_PAY_EXPRESS_EXPERIMENT_KEY,
61
- variant
61
+ variant,
62
+ ...experimentKey ? { experiment_key: experimentKey } : {}
62
63
  });
63
64
  };
64
65
  var trackExpressWalletImpression = (skuId, { entryPoint, country }) => {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Reads Amplitude experiment run key from Engagement SSR page props.
3
+ *
4
+ * Engagement already stores full fetchVariants entries on
5
+ * `window.__NEXT_DATA__.props.pageProps.experiments` (including
6
+ * `metadata.experimentKey`). Avoids extending the CDN bridge API.
7
+ */
8
+ export declare const getExperimentKeyFromNextData: (flagKey: string) => string | undefined;
@@ -0,0 +1,9 @@
1
+ // src/utils/getExperimentKeyFromNextData.ts
2
+ var getExperimentKeyFromNextData = (flagKey) => {
3
+ const experiments = window.__NEXT_DATA__?.props?.pageProps?.experiments;
4
+ const experimentKey = experiments?.[flagKey]?.metadata?.experimentKey;
5
+ return typeof experimentKey === "string" ? experimentKey : void 0;
6
+ };
7
+ export {
8
+ getExperimentKeyFromNextData
9
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@economist/web-apple-pay",
3
3
  "description": "Web component package for Apple Pay checkout UI",
4
- "version": "1.9.3",
4
+ "version": "1.9.4",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",