@se-studio/ab-testing 1.0.59 → 1.0.61
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/CHANGELOG.md +6 -0
- package/dist/components/AbTestReporter.d.ts.map +1 -1
- package/dist/components/AbTestReporter.js +0 -8
- package/dist/components/AbTestReporter.js.map +1 -1
- package/dist/components/AbTestUtmScript.d.ts +13 -0
- package/dist/components/AbTestUtmScript.d.ts.map +1 -0
- package/dist/components/AbTestUtmScript.js +34 -0
- package/dist/components/AbTestUtmScript.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +20 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbTestReporter.d.ts","sourceRoot":"","sources":["../../src/components/AbTestReporter.tsx"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,
|
|
1
|
+
{"version":3,"file":"AbTestReporter.d.ts","sourceRoot":"","sources":["../../src/components/AbTestReporter.tsx"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,SAgC7B"}
|
|
@@ -13,14 +13,6 @@ export function AbTestReporter() {
|
|
|
13
13
|
console.log('[A/B reporter] No active tests on this page');
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
// Update browser URL with utm_content so third-party scripts can read it
|
|
17
|
-
const url = new URL(window.location.href);
|
|
18
|
-
const firstAssignment = assignments[0];
|
|
19
|
-
if (firstAssignment) {
|
|
20
|
-
const utmContent = `${firstAssignment.test_label}:${firstAssignment.test_path}`;
|
|
21
|
-
url.searchParams.set('utm_content', utmContent);
|
|
22
|
-
history.replaceState(null, '', url.toString());
|
|
23
|
-
}
|
|
24
16
|
for (const assignment of assignments) {
|
|
25
17
|
console.log(`[A/B reporter] Test "${assignment.test_label}" (${assignment.testId})`, {
|
|
26
18
|
variant: assignment.test_path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbTestReporter.js","sourceRoot":"","sources":["../../src/components/AbTestReporter.tsx"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,yDAAyD;QACzD,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,
|
|
1
|
+
{"version":3,"file":"AbTestReporter.js","sourceRoot":"","sources":["../../src/components/AbTestReporter.tsx"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,yDAAyD;QACzD,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,wBAAwB,UAAU,CAAC,UAAU,MAAM,UAAU,CAAC,MAAM,GAAG,EAAE;gBACnF,OAAO,EAAE,UAAU,CAAC,SAAS;gBAC7B,IAAI,EAAE,UAAU,CAAC,aAAa;aAC/B,CAAC,CAAC;YAEH,wBAAwB;YACtB,MAA6C,CAAC,SAAmC,EAAE,IAAI,CAAC;gBACxF,KAAK,EAAE,uBAAuB;gBAC9B,aAAa,EAAE,UAAU,CAAC,MAAM;gBAChC,eAAe,EAAE,UAAU,CAAC,UAAU;gBACtC,UAAU,EAAE,UAAU,CAAC,SAAS;gBAChC,WAAW,EAAE,GAAG,UAAU,CAAC,UAAU,IAAI,UAAU,CAAC,SAAS,EAAE;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface AbTestUtmScriptProps {
|
|
2
|
+
cookieName?: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Inline script that sets utm_content on the browser URL as early as possible
|
|
6
|
+
* (before React hydration) so GTM scripts can read it on initial page load.
|
|
7
|
+
*
|
|
8
|
+
* Must be rendered in the root layout only — Next.js requires
|
|
9
|
+
* `strategy="beforeInteractive"` scripts to live in the root layout.
|
|
10
|
+
*/
|
|
11
|
+
export declare function AbTestUtmScript({ cookieName }: AbTestUtmScriptProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=AbTestUtmScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbTestUtmScript.d.ts","sourceRoot":"","sources":["../../src/components/AbTestUtmScript.tsx"],"names":[],"mappings":"AAEA,UAAU,oBAAoB;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,UAA2B,EAAE,EAAE,oBAAoB,2CAyBpF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Script from 'next/script';
|
|
3
|
+
/**
|
|
4
|
+
* Inline script that sets utm_content on the browser URL as early as possible
|
|
5
|
+
* (before React hydration) so GTM scripts can read it on initial page load.
|
|
6
|
+
*
|
|
7
|
+
* Must be rendered in the root layout only — Next.js requires
|
|
8
|
+
* `strategy="beforeInteractive"` scripts to live in the root layout.
|
|
9
|
+
*/
|
|
10
|
+
export function AbTestUtmScript({ cookieName = 'ab-test-info' }) {
|
|
11
|
+
return (_jsx(Script, { id: "ab-test-utm", strategy: "beforeInteractive", children: `
|
|
12
|
+
(function() {
|
|
13
|
+
try {
|
|
14
|
+
if (window.location.search.indexOf('utm_content=') !== -1) return;
|
|
15
|
+
var m = document.cookie.match(new RegExp('(^| )${cookieName}=([^;]+)'));
|
|
16
|
+
if (!m) return;
|
|
17
|
+
var a = JSON.parse(decodeURIComponent(m[2]));
|
|
18
|
+
var p = window.location.pathname.replace(/\\/$/, '') || '/';
|
|
19
|
+
var parts = [];
|
|
20
|
+
for (var id in a) {
|
|
21
|
+
var t = a[id];
|
|
22
|
+
var op = (t.original_path || '').replace(/\\/$/, '') || '/';
|
|
23
|
+
if (op === p) parts.push(t.test_label + ':' + t.test_path);
|
|
24
|
+
}
|
|
25
|
+
if (parts.length > 0) {
|
|
26
|
+
var url = new URL(window.location.href);
|
|
27
|
+
url.searchParams.set('utm_content', parts.join(','));
|
|
28
|
+
window.history.replaceState(window.history.state, '', url.toString());
|
|
29
|
+
}
|
|
30
|
+
} catch(e) {}
|
|
31
|
+
})();
|
|
32
|
+
` }));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=AbTestUtmScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbTestUtmScript.js","sourceRoot":"","sources":["../../src/components/AbTestUtmScript.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAMjC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,UAAU,GAAG,cAAc,EAAwB;IACnF,OAAO,CACL,KAAC,MAAM,IAAC,EAAE,EAAC,aAAa,EAAC,QAAQ,EAAC,mBAAmB,YAAE;;;;qDAIN,UAAU;;;;;;;;;;;;;;;;;KAiB1D,GAAU,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { useAbTestAssignments } from './hooks';
|
|
|
10
10
|
export type { AbTestMiddlewareConfig, AbTestResult, CachedAbTest, StaticAbTestMiddlewareOptions, TestsCache, } from './middleware';
|
|
11
11
|
export { clearTestCache, computeCachedTest, createAbTestMiddleware, createAssignment, createStaticAbTestMiddleware, DEFAULT_COOKIE_MAX_AGE, DEFAULT_COOKIE_NAME, getAssignment, getCachedTests, getTestCacheState, isValidAssignment, normalizePath, parseCookie, processAbTestRequest, readCookieFromDocument, selectVariant, serializeCookie, setAssignment, } from './middleware';
|
|
12
12
|
export type { AbTest, AbTestAssignment, AbTestCookie, AbTestVariant, AbTestVariantConfig, IBlobStore, } from './types';
|
|
13
|
+
export { findCanonicalPath } from './utils';
|
|
13
14
|
export type { RawPageTest, WebhookHandlerConfig, WebhookResult, } from './webhook';
|
|
14
15
|
export { createWebhookHandler, processAbTestWebhook, transformPageTest, } from './webhook';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAEnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,6BAA6B,EAC7B,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,UAAU,GACX,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAEnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACV,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,6BAA6B,EAC7B,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,UAAU,GACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,aAAa,GACd,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
export { useAbTestAssignments } from './hooks';
|
|
10
10
|
// Re-export middleware utilities
|
|
11
11
|
export { clearTestCache, computeCachedTest, createAbTestMiddleware, createAssignment, createStaticAbTestMiddleware, DEFAULT_COOKIE_MAX_AGE, DEFAULT_COOKIE_NAME, getAssignment, getCachedTests, getTestCacheState, isValidAssignment, normalizePath, parseCookie, processAbTestRequest, readCookieFromDocument, selectVariant, serializeCookie, setAssignment, } from './middleware';
|
|
12
|
+
// Utilities
|
|
13
|
+
export { findCanonicalPath } from './utils';
|
|
12
14
|
// Re-export webhook utilities
|
|
13
15
|
export { createWebhookHandler, processAbTestWebhook, transformPageTest, } from './webhook';
|
|
14
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,kBAAkB;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAQ/C,iCAAiC;AACjC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,kBAAkB;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAQ/C,iCAAiC;AACjC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AAUtB,YAAY;AACZ,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAM5C,8BAA8B;AAC9B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CachedAbTest } from './middleware/types';
|
|
2
|
+
/**
|
|
3
|
+
* Given a testsByPath map and a variant slug, returns the canonical
|
|
4
|
+
* (user-facing) path that owns the variant.
|
|
5
|
+
*
|
|
6
|
+
* Useful in page-test route handlers to set the correct canonical URL
|
|
7
|
+
* in metadata rather than exposing the internal variant path.
|
|
8
|
+
*
|
|
9
|
+
* @returns The canonical path (e.g. '/services/'), or undefined if not found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function findCanonicalPath(testsByPath: Record<string, CachedAbTest[]>, variantSlug: string): string | undefined;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAC3C,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CASpB"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a testsByPath map and a variant slug, returns the canonical
|
|
3
|
+
* (user-facing) path that owns the variant.
|
|
4
|
+
*
|
|
5
|
+
* Useful in page-test route handlers to set the correct canonical URL
|
|
6
|
+
* in metadata rather than exposing the internal variant path.
|
|
7
|
+
*
|
|
8
|
+
* @returns The canonical path (e.g. '/services/'), or undefined if not found.
|
|
9
|
+
*/
|
|
10
|
+
export function findCanonicalPath(testsByPath, variantSlug) {
|
|
11
|
+
for (const [controlPath, tests] of Object.entries(testsByPath)) {
|
|
12
|
+
for (const test of tests) {
|
|
13
|
+
if (test.variants.some((v) => v.slug === variantSlug)) {
|
|
14
|
+
return controlPath.endsWith('/') ? controlPath : `${controlPath}/`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,WAA2C,EAC3C,WAAmB;IAEnB,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;gBACtD,OAAO,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|