@elevateab/sdk 1.2.7 → 1.3.1
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/README.md +97 -30
- package/dist/cartAttributes-APUF5Y5N.js +3 -0
- package/dist/cartAttributes-OFPJ33X2.js +2 -0
- package/dist/chunk-5JX7O5JL.js +18 -0
- package/dist/chunk-5JX7O5JL.js.map +1 -0
- package/dist/{chunk-XXNIBCJ6.js → chunk-NDGAU23Z.js} +2 -2
- package/dist/chunk-U2FG4EEA.js +19 -0
- package/dist/chunk-U2FG4EEA.js.map +1 -0
- package/dist/hydrogen.cjs +2 -2
- package/dist/hydrogen.cjs.map +1 -1
- package/dist/hydrogen.js +1 -1
- package/dist/index.cjs +30 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +315 -311
- package/dist/index.d.ts +315 -311
- package/dist/index.js +29 -24
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +30 -25
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +129 -71
- package/dist/next.d.ts +129 -71
- package/dist/next.js +29 -24
- package/dist/next.js.map +1 -1
- package/dist/vite.cjs +2 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +28 -0
- package/dist/vite.d.ts +28 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/package.json +8 -2
- package/dist/cartAttributes-4XA3JSEP.js +0 -2
- package/dist/cartAttributes-NW2TWOYC.js +0 -3
- package/dist/chunk-4D5I75NE.js +0 -19
- package/dist/chunk-4D5I75NE.js.map +0 -1
- package/dist/chunk-VUGOZ5MR.js +0 -18
- package/dist/chunk-VUGOZ5MR.js.map +0 -1
- /package/dist/{cartAttributes-4XA3JSEP.js.map → cartAttributes-APUF5Y5N.js.map} +0 -0
- /package/dist/{cartAttributes-NW2TWOYC.js.map → cartAttributes-OFPJ33X2.js.map} +0 -0
- /package/dist/{chunk-XXNIBCJ6.js.map → chunk-NDGAU23Z.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ interface BackendVariation {
|
|
|
81
81
|
excludePathnames?: string[];
|
|
82
82
|
};
|
|
83
83
|
splitUrlTestLinks?: Record<string, string>;
|
|
84
|
-
content?:
|
|
84
|
+
content?: ContentTestData;
|
|
85
85
|
checkout?: {
|
|
86
86
|
banner?: {
|
|
87
87
|
title: string;
|
|
@@ -93,12 +93,119 @@ interface BackendVariation {
|
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Content change - modifies existing elements (text, styles, attributes)
|
|
98
|
+
*/
|
|
99
|
+
interface ContentChange {
|
|
100
|
+
/** CSS selector to target the element */
|
|
101
|
+
selector: string;
|
|
102
|
+
/** Text/HTML content to replace - supports responsive variants */
|
|
103
|
+
content?: {
|
|
104
|
+
/** Desktop/large screen content */
|
|
105
|
+
lg: string;
|
|
106
|
+
/** Mobile/small screen content (optional) */
|
|
107
|
+
sm?: string;
|
|
108
|
+
};
|
|
109
|
+
/** CSS styles to apply - supports responsive variants */
|
|
110
|
+
style?: {
|
|
111
|
+
/** Desktop/large screen styles */
|
|
112
|
+
lg: Record<string, string>;
|
|
113
|
+
/** Mobile/small screen styles (optional) */
|
|
114
|
+
sm?: Record<string, string>;
|
|
115
|
+
};
|
|
116
|
+
/** HTML attributes to set on the element */
|
|
117
|
+
attributes?: Record<string, string>;
|
|
118
|
+
/** Pathnames where this change applies (supports wildcards like "*", "*\/products\/*") */
|
|
119
|
+
pathnames?: string[];
|
|
120
|
+
/** If true, applies to all matching elements; otherwise only first match */
|
|
121
|
+
applyAll?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Content element - injects new HTML elements into the page
|
|
125
|
+
*/
|
|
126
|
+
interface ContentElement {
|
|
127
|
+
/** Unique identifier for this element */
|
|
128
|
+
id: string;
|
|
129
|
+
/** HTML tag name (e.g., "div", "span", "p") */
|
|
130
|
+
tagName: string;
|
|
131
|
+
/** Element type: "text" for text content, "container" for nested elements */
|
|
132
|
+
kind: "text" | "container";
|
|
133
|
+
/** Text content (for kind="text") */
|
|
134
|
+
content?: string;
|
|
135
|
+
/** Inline styles to apply */
|
|
136
|
+
style?: Record<string, string>;
|
|
137
|
+
/** HTML attributes to set */
|
|
138
|
+
attributes?: Record<string, string>;
|
|
139
|
+
/** Child elements (for kind="container") */
|
|
140
|
+
childrens?: ContentElement[];
|
|
141
|
+
/** Selector configuration for placement */
|
|
142
|
+
selector: {
|
|
143
|
+
/** CSS selector for the target element */
|
|
144
|
+
target: string;
|
|
145
|
+
/** Where to place relative to target */
|
|
146
|
+
placement: "before" | "after";
|
|
147
|
+
/** Pathnames where this element should appear */
|
|
148
|
+
pathnames?: string[];
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Content block - renders a component (future: React components)
|
|
153
|
+
* Currently deferred to v2 - blocks require dynamic component loading
|
|
154
|
+
*/
|
|
155
|
+
interface ContentBlock {
|
|
156
|
+
/** Unique identifier for this block */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Block type identifier (maps to a component) */
|
|
159
|
+
type: string;
|
|
160
|
+
/** URL to load the block component from */
|
|
161
|
+
url: string;
|
|
162
|
+
/** Options/props to pass to the block component */
|
|
163
|
+
options: Record<string, unknown>;
|
|
164
|
+
/** Selector configuration for placement */
|
|
165
|
+
selector: {
|
|
166
|
+
/** CSS selector for the target element */
|
|
167
|
+
target: string;
|
|
168
|
+
/** Where to place relative to target */
|
|
169
|
+
placement: "before" | "after";
|
|
170
|
+
/** Pathnames where this block should appear */
|
|
171
|
+
pathnames?: string[];
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Custom code injection - CSS and/or JavaScript to inject
|
|
176
|
+
*/
|
|
177
|
+
interface ContentCustomCode {
|
|
178
|
+
/** Unique identifier for this code block */
|
|
179
|
+
id: string;
|
|
180
|
+
/** CSS code to inject into <head> */
|
|
181
|
+
css?: string;
|
|
182
|
+
/** JavaScript code to inject and execute */
|
|
183
|
+
js?: string;
|
|
184
|
+
/** Pathnames where this code should run (supports wildcards) */
|
|
185
|
+
pathnames?: string[];
|
|
186
|
+
/** Pathnames to exclude from running this code */
|
|
187
|
+
excludePathnames?: string[];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Complete content test data structure
|
|
191
|
+
*/
|
|
192
|
+
interface ContentTestData {
|
|
193
|
+
/** Text/style/attribute modifications to existing elements */
|
|
194
|
+
changes: ContentChange[];
|
|
195
|
+
/** New HTML elements to inject */
|
|
196
|
+
elements: ContentElement[];
|
|
197
|
+
/** Component blocks to render (v2 feature) */
|
|
198
|
+
blocks: ContentBlock[];
|
|
199
|
+
/** Custom CSS/JS code to inject */
|
|
200
|
+
customCodes: ContentCustomCode[];
|
|
201
|
+
}
|
|
96
202
|
interface Test {
|
|
97
203
|
testId: string;
|
|
98
204
|
name: string;
|
|
99
205
|
enabled: boolean;
|
|
100
206
|
type: string;
|
|
101
207
|
variations: Variation[];
|
|
208
|
+
data?: any;
|
|
102
209
|
}
|
|
103
210
|
interface Variation {
|
|
104
211
|
id: string;
|
|
@@ -108,6 +215,16 @@ interface Variation {
|
|
|
108
215
|
productId?: string;
|
|
109
216
|
handle?: string;
|
|
110
217
|
price?: string;
|
|
218
|
+
/** Variant-specific prices for PRICE_PLUS tests: { [variantId]: { main, price, compare } } */
|
|
219
|
+
prices?: Record<string, {
|
|
220
|
+
main: string;
|
|
221
|
+
price: Record<string, string>;
|
|
222
|
+
compare: Record<string, string | null>;
|
|
223
|
+
}>;
|
|
224
|
+
/** URLs for SPLIT_URL tests */
|
|
225
|
+
splitUrlTestLinks?: string[];
|
|
226
|
+
/** Content test data for CONTENT tests */
|
|
227
|
+
content?: ContentTestData;
|
|
111
228
|
/** Convenience flag: true if this is variation A (index 0) */
|
|
112
229
|
isA?: boolean;
|
|
113
230
|
/** Convenience flag: true if this is variation B (index 1) */
|
|
@@ -184,6 +301,15 @@ interface ElevateContextValue {
|
|
|
184
301
|
isPreviewMode?: boolean;
|
|
185
302
|
/** Current preview test ID if in preview mode */
|
|
186
303
|
previewTestId?: string | null;
|
|
304
|
+
/** Full preview state with forced assignments */
|
|
305
|
+
previewState?: {
|
|
306
|
+
isPreview: boolean;
|
|
307
|
+
previewTestId: string | null;
|
|
308
|
+
forcedAssignments: Record<string, string>;
|
|
309
|
+
previewedViews: Record<string, boolean>;
|
|
310
|
+
} | null;
|
|
311
|
+
/** Selectors configuration for DOM manipulation */
|
|
312
|
+
selectors?: unknown;
|
|
187
313
|
/** User's detected country code */
|
|
188
314
|
countryCode?: string | null;
|
|
189
315
|
}
|
|
@@ -671,172 +797,27 @@ interface CartAttributeInput {
|
|
|
671
797
|
/** Attribute value (JSON string for complex data) */
|
|
672
798
|
value: string;
|
|
673
799
|
}
|
|
674
|
-
/**
|
|
675
|
-
* @deprecated Use TrackPageViewParams instead
|
|
676
|
-
*/
|
|
677
|
-
interface TrackingEvent {
|
|
678
|
-
experimentId: string;
|
|
679
|
-
variantId: string;
|
|
680
|
-
userId: string;
|
|
681
|
-
timestamp: number;
|
|
682
|
-
metadata?: Record<string, unknown>;
|
|
683
|
-
}
|
|
684
800
|
|
|
685
|
-
/**
|
|
686
|
-
* Assigns a variant based on weighted distribution
|
|
687
|
-
*/
|
|
688
|
-
declare function assignVariant(variations: Variation[], userId: string): Variation;
|
|
689
801
|
declare function hashString(str: string): number;
|
|
690
|
-
declare function validateConfig(config: Test): boolean;
|
|
691
|
-
declare function generateExperimentId(name: string): string;
|
|
692
|
-
declare function calculateRevenueLift(controlRevenue: number, variantRevenue: number, controlSampleSize: number, variantSampleSize: number): {
|
|
693
|
-
lift: number;
|
|
694
|
-
confidence: number;
|
|
695
|
-
};
|
|
696
802
|
|
|
697
|
-
/**
|
|
698
|
-
* Cookie and Session Storage utilities
|
|
699
|
-
*/
|
|
700
|
-
/**
|
|
701
|
-
* Generate a UUID v4
|
|
702
|
-
*/
|
|
703
803
|
declare function uuidv4(): string;
|
|
704
|
-
/**
|
|
705
|
-
* Set a cookie with 1 year expiration
|
|
706
|
-
*/
|
|
707
804
|
declare function setCookie(name: string, value: string): void;
|
|
708
|
-
/**
|
|
709
|
-
* Get a cookie value by name
|
|
710
|
-
*/
|
|
711
805
|
declare function getCookie(name: string): string | null;
|
|
712
|
-
/**
|
|
713
|
-
* Get a JSON-parsed cookie value
|
|
714
|
-
*/
|
|
715
806
|
declare function getJsonCookie<T = Record<string, unknown>>(name: string): T | null;
|
|
716
|
-
/**
|
|
717
|
-
* Delete a cookie
|
|
718
|
-
*/
|
|
719
807
|
declare function deleteCookie(cookieName: string): void;
|
|
720
|
-
/**
|
|
721
|
-
* Set a session storage item
|
|
722
|
-
*/
|
|
723
808
|
declare function setSessionItem(name: string, value: unknown): void;
|
|
724
|
-
/**
|
|
725
|
-
* Get a session storage item
|
|
726
|
-
*/
|
|
727
809
|
declare function getSessionItem(name: string): string | null;
|
|
728
|
-
/**
|
|
729
|
-
* Get a JSON-parsed session storage item
|
|
730
|
-
*/
|
|
731
810
|
declare function getJsonSessionItem<T = unknown>(name: string): T | null;
|
|
732
|
-
/**
|
|
733
|
-
* Initialize visitor ID - creates eabUserId cookie if it doesn't exist
|
|
734
|
-
*/
|
|
735
811
|
declare function initializeVisitorId(): string;
|
|
736
|
-
/**
|
|
737
|
-
* Get or create visitor ID
|
|
738
|
-
*/
|
|
739
812
|
declare function getVisitorId(): string;
|
|
740
|
-
/**
|
|
741
|
-
* Initialize session ID - creates eabSessionId in sessionStorage if it doesn't exist
|
|
742
|
-
*/
|
|
743
813
|
declare function initializeSessionId(): string;
|
|
744
|
-
/**
|
|
745
|
-
* Get or create session ID
|
|
746
|
-
*/
|
|
747
814
|
declare function getSessionId(): string;
|
|
748
|
-
/**
|
|
749
|
-
* Store referrer and entry page data in sessionStorage
|
|
750
|
-
*/
|
|
751
815
|
declare function setReferrerData(referrer: string, entryPage: string): void;
|
|
752
|
-
/**
|
|
753
|
-
* Get referrer data from sessionStorage
|
|
754
|
-
*/
|
|
755
816
|
declare function getReferrerData(): {
|
|
756
817
|
referrer: string;
|
|
757
818
|
entryPage: string;
|
|
758
819
|
};
|
|
759
820
|
|
|
760
|
-
/**
|
|
761
|
-
* Variant assignment logic
|
|
762
|
-
*/
|
|
763
|
-
|
|
764
|
-
interface TestList {
|
|
765
|
-
[testId: string]: string;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Get the test list from ABTL cookie
|
|
769
|
-
*/
|
|
770
|
-
declare function getTestList(): TestList;
|
|
771
|
-
/**
|
|
772
|
-
* Save test list to ABTL cookie
|
|
773
|
-
*/
|
|
774
|
-
declare function saveTestList(testList: TestList): void;
|
|
775
|
-
/**
|
|
776
|
-
* Get assigned variant for a test from ABTL cookie
|
|
777
|
-
*/
|
|
778
|
-
declare function getAssignedVariant(testId: string): string | null;
|
|
779
|
-
/**
|
|
780
|
-
* Assign and persist variant for a test
|
|
781
|
-
*/
|
|
782
|
-
declare function assignAndPersistVariant(testId: string, test: Test, userId: string): Variation | null;
|
|
783
|
-
/**
|
|
784
|
-
* Check if test should be shown based on traffic percentage
|
|
785
|
-
*/
|
|
786
|
-
declare function shouldShowTest(test: Test): boolean;
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Tracking utilities for views and participation
|
|
790
|
-
*/
|
|
791
|
-
/**
|
|
792
|
-
* Track unique view for a test (ABAU cookie)
|
|
793
|
-
*/
|
|
794
|
-
declare function trackUniqueView(testId: string): void;
|
|
795
|
-
/**
|
|
796
|
-
* Track session view for a test (ABAV session storage)
|
|
797
|
-
*/
|
|
798
|
-
declare function trackSessionView(testId: string): void;
|
|
799
|
-
/**
|
|
800
|
-
* Track both unique and session views
|
|
801
|
-
*/
|
|
802
|
-
declare function trackViews(testId: string): void;
|
|
803
|
-
/**
|
|
804
|
-
* Check if test has been viewed in this session
|
|
805
|
-
*/
|
|
806
|
-
declare function hasSessionView(testId: string): boolean;
|
|
807
|
-
/**
|
|
808
|
-
* Check if test has a unique view
|
|
809
|
-
*/
|
|
810
|
-
declare function hasUniqueView(testId: string): boolean;
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* Condition checking utilities for targeting and filtering
|
|
814
|
-
*/
|
|
815
|
-
/**
|
|
816
|
-
* Detect device type
|
|
817
|
-
*/
|
|
818
|
-
declare function getDeviceType(): "desktop" | "tablet" | "mobile";
|
|
819
|
-
/**
|
|
820
|
-
* Check if Facebook in-app browser
|
|
821
|
-
*/
|
|
822
|
-
declare function checkFacebookBrowser(): boolean;
|
|
823
|
-
/**
|
|
824
|
-
* Check if Instagram in-app browser
|
|
825
|
-
*/
|
|
826
|
-
declare function checkInstagramBrowser(): boolean;
|
|
827
|
-
/**
|
|
828
|
-
* Check if TikTok in-app browser
|
|
829
|
-
*/
|
|
830
|
-
declare function checkTikTokBrowser(): boolean;
|
|
831
|
-
/**
|
|
832
|
-
* Check if Pinterest in-app browser
|
|
833
|
-
*/
|
|
834
|
-
declare function checkPinterestBrowser(): boolean;
|
|
835
|
-
/**
|
|
836
|
-
* Get traffic source
|
|
837
|
-
*/
|
|
838
|
-
declare function getTrafficSource(): string;
|
|
839
|
-
|
|
840
821
|
/**
|
|
841
822
|
* Preview Mode Utilities
|
|
842
823
|
*
|
|
@@ -894,6 +875,51 @@ declare function clearPreviewMode(): void;
|
|
|
894
875
|
*/
|
|
895
876
|
declare function isInPreviewMode(): boolean;
|
|
896
877
|
|
|
878
|
+
interface TestList {
|
|
879
|
+
[testId: string]: string;
|
|
880
|
+
}
|
|
881
|
+
declare function getTestList(): TestList;
|
|
882
|
+
declare function saveTestList(testList: TestList): void;
|
|
883
|
+
declare function getAssignedVariant(testId: string): string | null;
|
|
884
|
+
declare function assignAndPersistVariant(testId: string, test: Test, userId: string, previewState?: PreviewState): Variation | null;
|
|
885
|
+
declare function canAssignToTest(testId: string, allTests: Test[]): boolean;
|
|
886
|
+
declare function shouldShowTest(test: Test, allTests?: Test[]): boolean;
|
|
887
|
+
declare function assignAllTests(config: ElevateConfig, previewState?: PreviewState | null): void;
|
|
888
|
+
|
|
889
|
+
declare function trackUniqueView(testId: string): void;
|
|
890
|
+
declare function trackSessionView(testId: string): void;
|
|
891
|
+
declare function trackViews(testId: string): void;
|
|
892
|
+
declare function hasSessionView(testId: string): boolean;
|
|
893
|
+
declare function hasUniqueView(testId: string): boolean;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Condition checking utilities for targeting and filtering
|
|
897
|
+
*/
|
|
898
|
+
/**
|
|
899
|
+
* Detect device type
|
|
900
|
+
*/
|
|
901
|
+
declare function getDeviceType(): "desktop" | "tablet" | "mobile";
|
|
902
|
+
/**
|
|
903
|
+
* Check if Facebook in-app browser
|
|
904
|
+
*/
|
|
905
|
+
declare function checkFacebookBrowser(): boolean;
|
|
906
|
+
/**
|
|
907
|
+
* Check if Instagram in-app browser
|
|
908
|
+
*/
|
|
909
|
+
declare function checkInstagramBrowser(): boolean;
|
|
910
|
+
/**
|
|
911
|
+
* Check if TikTok in-app browser
|
|
912
|
+
*/
|
|
913
|
+
declare function checkTikTokBrowser(): boolean;
|
|
914
|
+
/**
|
|
915
|
+
* Check if Pinterest in-app browser
|
|
916
|
+
*/
|
|
917
|
+
declare function checkPinterestBrowser(): boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Get traffic source
|
|
920
|
+
*/
|
|
921
|
+
declare function getTrafficSource(): string;
|
|
922
|
+
|
|
897
923
|
/**
|
|
898
924
|
* Geo-targeting Utilities
|
|
899
925
|
*
|
|
@@ -968,67 +994,18 @@ declare const REGIONS: {
|
|
|
968
994
|
readonly LATAM: readonly ["MX", "BR", "AR", "CL", "CO", "PE"];
|
|
969
995
|
};
|
|
970
996
|
|
|
997
|
+
interface SplitUrlScriptOptions {
|
|
998
|
+
configUrl: string;
|
|
999
|
+
timeout?: number;
|
|
1000
|
+
}
|
|
1001
|
+
declare function getSplitUrlBlockingScript(options: SplitUrlScriptOptions): string;
|
|
971
1002
|
/**
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
* Prevents visual flickering during A/B test assignment by hiding content
|
|
975
|
-
* until the variant is determined. Uses a CSS-based approach for performance.
|
|
976
|
-
*
|
|
977
|
-
* Note: Called "preventFlickering" in our API to differentiate from competitors.
|
|
978
|
-
*/
|
|
979
|
-
/**
|
|
980
|
-
* Inject the flicker prevention CSS styles
|
|
981
|
-
* This should be called as early as possible (ideally in <head>)
|
|
982
|
-
*/
|
|
983
|
-
declare function injectFlickerStyles(timeout?: number): void;
|
|
984
|
-
/**
|
|
985
|
-
* Hide the page/element to prevent flicker
|
|
986
|
-
* Call this before test assignment begins
|
|
987
|
-
*/
|
|
988
|
-
declare function hideForFlicker(selector?: string): void;
|
|
989
|
-
/**
|
|
990
|
-
* Show the page/element after test assignment is complete
|
|
991
|
-
* Call this after variant is determined
|
|
992
|
-
*/
|
|
993
|
-
declare function revealAfterFlicker(selector?: string): void;
|
|
994
|
-
/**
|
|
995
|
-
* Setup flicker prevention with automatic reveal
|
|
996
|
-
* Returns a function to call when assignment is complete
|
|
997
|
-
*
|
|
998
|
-
* @param selector - CSS selector for element to hide (default: "body")
|
|
999
|
-
* @param timeout - Maximum time to wait before revealing (default: 3000ms)
|
|
1000
|
-
* @returns Function to call when test assignment is complete
|
|
1001
|
-
*
|
|
1002
|
-
* @example
|
|
1003
|
-
* ```tsx
|
|
1004
|
-
* // In your app initialization
|
|
1005
|
-
* const reveal = setupFlickerPrevention();
|
|
1006
|
-
*
|
|
1007
|
-
* // After test assignment
|
|
1008
|
-
* reveal();
|
|
1009
|
-
* ```
|
|
1010
|
-
*/
|
|
1011
|
-
declare function setupFlickerPrevention(selector?: string, timeout?: number): () => void;
|
|
1012
|
-
/**
|
|
1013
|
-
* Remove all flicker prevention styles and classes
|
|
1014
|
-
* Useful for cleanup or when disabling the feature
|
|
1015
|
-
*/
|
|
1016
|
-
declare function cleanupFlickerPrevention(): void;
|
|
1017
|
-
/**
|
|
1018
|
-
* Check if flicker prevention is currently active
|
|
1019
|
-
*/
|
|
1020
|
-
declare function isFlickerPreventionActive(): boolean;
|
|
1021
|
-
/**
|
|
1022
|
-
* Script snippet for inline injection in <head>
|
|
1023
|
-
* Use this when you need synchronous flicker prevention before React hydrates
|
|
1003
|
+
* Process Split URL tests and redirect if needed
|
|
1004
|
+
* This is called automatically from ElevateProvider on mount.
|
|
1024
1005
|
*
|
|
1025
|
-
* @
|
|
1026
|
-
* ```tsx
|
|
1027
|
-
* // In your _document.tsx or layout.tsx
|
|
1028
|
-
* <script dangerouslySetInnerHTML={{ __html: getFlickerPreventionScript() }} />
|
|
1029
|
-
* ```
|
|
1006
|
+
* @returns true if a redirect was triggered, false otherwise
|
|
1030
1007
|
*/
|
|
1031
|
-
declare function
|
|
1008
|
+
declare function processSplitUrlTests(config: ElevateConfig, previewState?: PreviewState | null | undefined): boolean;
|
|
1032
1009
|
|
|
1033
1010
|
/**
|
|
1034
1011
|
* Analytics utilities for parsing and extracting data from events
|
|
@@ -1156,6 +1133,57 @@ declare function isShopifyGid(value: string | null | undefined): boolean;
|
|
|
1156
1133
|
*/
|
|
1157
1134
|
declare function detectShopifyCurrency(): string | undefined;
|
|
1158
1135
|
|
|
1136
|
+
/**
|
|
1137
|
+
* Content Test Utilities
|
|
1138
|
+
*
|
|
1139
|
+
* Handles DOM manipulation for Content Tests (Visual Editor Experiments).
|
|
1140
|
+
* Automatically applies changes, injects elements, and runs custom code
|
|
1141
|
+
* based on the assigned variant's content configuration.
|
|
1142
|
+
*/
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Check if a pathname matches a wildcard pattern
|
|
1146
|
+
* Supports: "*" (all), "*\/products\/*" (contains), "*.json" (ends with)
|
|
1147
|
+
*/
|
|
1148
|
+
declare function matchesWildcardPattern(pathname: string, pattern: string): boolean;
|
|
1149
|
+
/**
|
|
1150
|
+
* Apply content changes to existing elements
|
|
1151
|
+
*/
|
|
1152
|
+
declare function applyContentChanges(changes: ContentChange[]): void;
|
|
1153
|
+
/**
|
|
1154
|
+
* Apply content elements (inject new HTML elements)
|
|
1155
|
+
*/
|
|
1156
|
+
declare function applyContentElements(elements: ContentElement[]): void;
|
|
1157
|
+
/**
|
|
1158
|
+
* Apply custom code (CSS and JS injection)
|
|
1159
|
+
*/
|
|
1160
|
+
declare function applyCustomCode(customCodes: ContentCustomCode[], nonce?: string): void;
|
|
1161
|
+
/**
|
|
1162
|
+
* Restore original elements (for responsive changes or cleanup)
|
|
1163
|
+
*/
|
|
1164
|
+
declare function restoreOriginalElements(): void;
|
|
1165
|
+
/**
|
|
1166
|
+
* Clean up all injected content
|
|
1167
|
+
*/
|
|
1168
|
+
declare function cleanupContentTests(): void;
|
|
1169
|
+
/**
|
|
1170
|
+
* Check if there are any active content tests
|
|
1171
|
+
*/
|
|
1172
|
+
declare function hasContentTests(config: ElevateConfig): boolean;
|
|
1173
|
+
/**
|
|
1174
|
+
* Process and apply all content tests
|
|
1175
|
+
* This is the main entry point called by ElevateProvider
|
|
1176
|
+
*/
|
|
1177
|
+
declare function processContentTests(config: ElevateConfig, previewState?: PreviewState | null, nonce?: string): void;
|
|
1178
|
+
/**
|
|
1179
|
+
* Re-process content tests (called on pathname change or resize)
|
|
1180
|
+
*/
|
|
1181
|
+
declare function reprocessContentTests(config: ElevateConfig, previewState?: PreviewState | null, nonce?: string): void;
|
|
1182
|
+
/**
|
|
1183
|
+
* Setup event listeners for content test re-processing
|
|
1184
|
+
*/
|
|
1185
|
+
declare function setupContentTestListeners(config: ElevateConfig, previewState?: PreviewState | null, nonce?: string): () => void;
|
|
1186
|
+
|
|
1159
1187
|
/**
|
|
1160
1188
|
* Cart attribute utilities for tagging carts with A/B test data
|
|
1161
1189
|
*
|
|
@@ -1426,9 +1454,87 @@ declare function usePageViewTracking(params: UsePageViewTrackingParams & {
|
|
|
1426
1454
|
pathname?: string;
|
|
1427
1455
|
}): void;
|
|
1428
1456
|
|
|
1457
|
+
interface HandlerContext {
|
|
1458
|
+
/** Current page URL */
|
|
1459
|
+
currentUrl: string;
|
|
1460
|
+
/** Detected product ID from URL (e.g., from /products/{handle}) */
|
|
1461
|
+
productId?: string;
|
|
1462
|
+
/** Product handle from URL */
|
|
1463
|
+
productHandle?: string;
|
|
1464
|
+
/** Currently selected variant ID */
|
|
1465
|
+
variantId?: string;
|
|
1466
|
+
/** Selectors configuration from backend */
|
|
1467
|
+
selectors?: unknown;
|
|
1468
|
+
/** Current currency code */
|
|
1469
|
+
currencyCode?: string;
|
|
1470
|
+
}
|
|
1471
|
+
interface HandlerVariantData {
|
|
1472
|
+
/** Price overrides for PRICE_PLUS tests */
|
|
1473
|
+
prices?: Record<string, {
|
|
1474
|
+
main: string;
|
|
1475
|
+
price: Record<string, string>;
|
|
1476
|
+
compare: Record<string, string | null>;
|
|
1477
|
+
}>;
|
|
1478
|
+
/** Matched product ID for PRICE_PLUS tests */
|
|
1479
|
+
matchedProductId?: string;
|
|
1480
|
+
/** Whether this handler was activated */
|
|
1481
|
+
handlerActivated?: boolean;
|
|
1482
|
+
/** Any additional data specific to the test type */
|
|
1483
|
+
[key: string]: unknown;
|
|
1484
|
+
}
|
|
1485
|
+
interface TestTypeHandler {
|
|
1486
|
+
/** Test type identifier (e.g., 'PRICE_PLUS', 'PAGE', 'CONTENT') */
|
|
1487
|
+
type: string;
|
|
1488
|
+
/**
|
|
1489
|
+
* Check if this handler should activate for the current context.
|
|
1490
|
+
* For PRICE_PLUS: checks if current product matches test's productIds
|
|
1491
|
+
* For PAGE: checks if current URL matches test's pathnames
|
|
1492
|
+
*/
|
|
1493
|
+
shouldActivate(test: Test, context: HandlerContext): boolean;
|
|
1494
|
+
/**
|
|
1495
|
+
* Apply the test effect (optional DOM manipulation).
|
|
1496
|
+
* For PRICE_PLUS: updates price elements using selectors
|
|
1497
|
+
* For PAGE: may handle redirects
|
|
1498
|
+
* For CONTENT: may swap content blocks
|
|
1499
|
+
*/
|
|
1500
|
+
applyEffect?(test: Test, variation: Variation, context: HandlerContext): void;
|
|
1501
|
+
/**
|
|
1502
|
+
* Return additional data to merge into the variant.
|
|
1503
|
+
* This data is available in useExperiment's return value.
|
|
1504
|
+
*/
|
|
1505
|
+
getVariantData(test: Test, variation: Variation, context: HandlerContext): HandlerVariantData;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
declare function registerHandler(handler: TestTypeHandler): void;
|
|
1509
|
+
declare function getHandler(type: string): TestTypeHandler | undefined;
|
|
1510
|
+
declare function getAllHandlers(): TestTypeHandler[];
|
|
1511
|
+
declare function hasHandler(type: string): boolean;
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Content Test Handler
|
|
1515
|
+
*
|
|
1516
|
+
* Handles CONTENT type tests (Visual Editor Experiments).
|
|
1517
|
+
* These tests modify page content without redirects - they can:
|
|
1518
|
+
* - Remove/hide elements
|
|
1519
|
+
* - Modify text/headings/descriptions
|
|
1520
|
+
* - Change CSS styles (colors, fonts, sizes)
|
|
1521
|
+
* - Add new HTML elements
|
|
1522
|
+
* - Modify attributes (href, src, etc.)
|
|
1523
|
+
* - Inject custom CSS/JS
|
|
1524
|
+
*/
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* Content test handler
|
|
1528
|
+
*
|
|
1529
|
+
* Note: Content test effects are applied by processContentTests in ElevateProvider,
|
|
1530
|
+
* not through the handler's applyEffect. This ensures all content tests are
|
|
1531
|
+
* processed together after variant assignment for better coordination.
|
|
1532
|
+
*/
|
|
1533
|
+
declare const contentHandler: TestTypeHandler;
|
|
1534
|
+
|
|
1429
1535
|
interface UseExperimentResult {
|
|
1430
|
-
/** The full variant object (null if not assigned) */
|
|
1431
|
-
variant: Variation | null;
|
|
1536
|
+
/** The full variant object with handler data (null if not assigned) */
|
|
1537
|
+
variant: (Variation & Record<string, unknown>) | null;
|
|
1432
1538
|
/** True while loading config */
|
|
1433
1539
|
isLoading: boolean;
|
|
1434
1540
|
/** True if assigned to control group */
|
|
@@ -1457,111 +1563,14 @@ interface UseExperimentResult {
|
|
|
1457
1563
|
declare function useExperiment(testId: string): UseExperimentResult;
|
|
1458
1564
|
|
|
1459
1565
|
interface ElevateProviderSimpleProps {
|
|
1460
|
-
/** Shopify store domain (e.g., "your-store.myshopify.com") */
|
|
1461
1566
|
storeId: string;
|
|
1462
|
-
/**
|
|
1463
|
-
* Storefront Access Token - Required for cart attribute tracking (order attribution)
|
|
1464
|
-
*
|
|
1465
|
-
* This is SAFE to use client-side - it's a public token with limited permissions.
|
|
1466
|
-
* Get it from: Shopify Admin → Settings → Apps → Develop apps
|
|
1467
|
-
*
|
|
1468
|
-
* Without this token, A/B tests work but orders won't be attributed to variants.
|
|
1469
|
-
*/
|
|
1470
1567
|
storefrontAccessToken?: string;
|
|
1471
|
-
/**
|
|
1472
|
-
* Enable flicker prevention - hides content until test assignment is complete
|
|
1473
|
-
* Prevents users from seeing content flash/change when variants load
|
|
1474
|
-
* @default false
|
|
1475
|
-
*/
|
|
1476
1568
|
preventFlickering?: boolean;
|
|
1477
|
-
/**
|
|
1478
|
-
* Timeout in milliseconds for flicker prevention failsafe
|
|
1479
|
-
* Content will show after this time even if assignment isn't complete
|
|
1480
|
-
* @default 3000
|
|
1481
|
-
*/
|
|
1482
1569
|
flickerTimeout?: number;
|
|
1570
|
+
nonce?: string;
|
|
1483
1571
|
children: React.ReactNode;
|
|
1484
1572
|
}
|
|
1485
|
-
|
|
1486
|
-
* ElevateProvider - Provides A/B test configuration to child components
|
|
1487
|
-
*
|
|
1488
|
-
* @example Next.js / Remix
|
|
1489
|
-
* ```tsx
|
|
1490
|
-
* <ElevateProvider
|
|
1491
|
-
* storeId="your-store.myshopify.com"
|
|
1492
|
-
* storefrontAccessToken="your-public-token"
|
|
1493
|
-
* >
|
|
1494
|
-
* <App />
|
|
1495
|
-
* </ElevateProvider>
|
|
1496
|
-
* ```
|
|
1497
|
-
*
|
|
1498
|
-
* @example Hydrogen (with Analytics.Provider)
|
|
1499
|
-
* ```tsx
|
|
1500
|
-
* <Analytics.Provider cart={cart} shop={shop} consent={consent}>
|
|
1501
|
-
* <ElevateProvider storeId="your-store.myshopify.com" storefrontAccessToken="token">
|
|
1502
|
-
* <ElevateAnalytics />
|
|
1503
|
-
* <App />
|
|
1504
|
-
* </ElevateProvider>
|
|
1505
|
-
* </Analytics.Provider>
|
|
1506
|
-
* ```
|
|
1507
|
-
*/
|
|
1508
|
-
declare function ElevateProvider({ storeId, storefrontAccessToken, preventFlickering, flickerTimeout, children, }: ElevateProviderSimpleProps): react_jsx_runtime.JSX.Element;
|
|
1509
|
-
|
|
1510
|
-
interface AntiFlickerScriptProps {
|
|
1511
|
-
/**
|
|
1512
|
-
* Maximum time (ms) to wait before showing content anyway (failsafe)
|
|
1513
|
-
* @default 3000
|
|
1514
|
-
*/
|
|
1515
|
-
timeout?: number;
|
|
1516
|
-
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Anti-flicker script component
|
|
1519
|
-
*
|
|
1520
|
-
* Renders a script tag that prevents content flash during A/B test loading.
|
|
1521
|
-
* Place this in your <head> element before any other scripts.
|
|
1522
|
-
*
|
|
1523
|
-
* @example Hydrogen (app/root.tsx)
|
|
1524
|
-
* ```tsx
|
|
1525
|
-
* import { AntiFlickerScript, ElevateProvider } from "@elevateab/sdk";
|
|
1526
|
-
*
|
|
1527
|
-
* export default function Root() {
|
|
1528
|
-
* return (
|
|
1529
|
-
* <html>
|
|
1530
|
-
* <head>
|
|
1531
|
-
* <AntiFlickerScript />
|
|
1532
|
-
* </head>
|
|
1533
|
-
* <body>
|
|
1534
|
-
* <ElevateProvider storeId="..." preventFlickering={true}>
|
|
1535
|
-
* <Outlet />
|
|
1536
|
-
* </ElevateProvider>
|
|
1537
|
-
* </body>
|
|
1538
|
-
* </html>
|
|
1539
|
-
* );
|
|
1540
|
-
* }
|
|
1541
|
-
* ```
|
|
1542
|
-
*
|
|
1543
|
-
* @example Next.js (app/layout.tsx)
|
|
1544
|
-
* ```tsx
|
|
1545
|
-
* import { AntiFlickerScript } from "@elevateab/sdk";
|
|
1546
|
-
* import { ElevateNextProvider } from "@elevateab/sdk/next";
|
|
1547
|
-
*
|
|
1548
|
-
* export default function RootLayout({ children }) {
|
|
1549
|
-
* return (
|
|
1550
|
-
* <html>
|
|
1551
|
-
* <head>
|
|
1552
|
-
* <AntiFlickerScript />
|
|
1553
|
-
* </head>
|
|
1554
|
-
* <body>
|
|
1555
|
-
* <ElevateNextProvider storeId="..." preventFlickering={true}>
|
|
1556
|
-
* {children}
|
|
1557
|
-
* </ElevateNextProvider>
|
|
1558
|
-
* </body>
|
|
1559
|
-
* </html>
|
|
1560
|
-
* );
|
|
1561
|
-
* }
|
|
1562
|
-
* ```
|
|
1563
|
-
*/
|
|
1564
|
-
declare function AntiFlickerScript({ timeout }: AntiFlickerScriptProps): react_jsx_runtime.JSX.Element;
|
|
1573
|
+
declare function ElevateProvider({ storeId, storefrontAccessToken, preventFlickering, flickerTimeout, nonce, children, }: ElevateProviderSimpleProps): react_jsx_runtime.JSX.Element;
|
|
1565
1574
|
|
|
1566
1575
|
/**
|
|
1567
1576
|
* Hook to access Elevate config from context
|
|
@@ -1569,10 +1578,5 @@ declare function AntiFlickerScript({ timeout }: AntiFlickerScriptProps): react_j
|
|
|
1569
1578
|
declare function useElevateConfig(): ElevateContextValue;
|
|
1570
1579
|
|
|
1571
1580
|
declare const VERSION = "1.1.2";
|
|
1572
|
-
declare const DEFAULT_CONFIG: {
|
|
1573
|
-
enabled: boolean;
|
|
1574
|
-
trackingEndpoint: string;
|
|
1575
|
-
cacheDuration: number;
|
|
1576
|
-
};
|
|
1577
1581
|
|
|
1578
|
-
export {
|
|
1582
|
+
export { type BackendConfig, type BackendTest, type BackendVariation, type BaseTrackingConfig, CART_ATTRIBUTES_UPDATE_MUTATION, COUNTRIES, type CartAttributeInput, type CartAttributesOptions, type CartItemInput, type CartItemPayload, type ContentBlock, type ContentChange, type ContentCustomCode, type ContentElement, type ContentTestData, type ElevateAnalyticsProps, type ElevateConfig, type ElevateContextValue, ElevateProvider, type ElevateProviderProps, type EventPayload, type ExperimentStatus, type GeoLocation, type HandlerContext, type HandlerVariantData, type NoteAttribute, type ParsedViewData, type PreviewState, REGIONS, type SplitUrlScriptOptions, type Test, type TestAssignment, type TestTypeHandler, type TrackAddToCartParams, type TrackCartViewParams, type TrackCheckoutCompletedParams, type TrackCheckoutStartedParams, type TrackPageViewParams, type TrackProductViewParams, type TrackRemoveFromCartParams, type TrackSearchSubmittedParams, type UseExperimentResult, type UsePageViewTrackingParams, VERSION, type Variation, applyContentChanges, applyContentElements, applyCustomCode, assignAllTests, assignAndPersistVariant, buildEabTestsParam, canAssignToTest, checkFacebookBrowser, checkFacebookInstagramBrowser, checkInstagramBrowser, checkPinterestBrowser, checkTikTokBrowser, checkVisitorIdParams, cleanCartToken, cleanupCartAttributes, cleanupContentTests, clearPreviewMode, contentHandler, deleteCookie, detectShopifyCurrency, extractCartToken, extractProductId, extractProductVariantId, extractShopifyId, extractShopifyType, getAllHandlers, getAssignedVariant, getCartAttributesPayload, getCookie, getCountryCode, getDeviceType, getGeoLocation, getHandler, getJsonCookie, getJsonSessionItem, getPageTypeFromPathname, getPreviewState, getPreviewVariation, getReferrerData, getSessionId, getSessionItem, getSplitUrlBlockingScript, getTestList, getTrafficSource, getUserAgentNoBrowser, getVisitorId, hasContentTests, hasHandler, hasSessionView, hasUniqueView, hashString, initAnalytics, initializeSessionId, initializeVisitorId, isCountryExcluded, isCountryIncluded, isInPreviewMode, isPreviewTest, isShopifyGid, matchesGeoTargeting, matchesWildcardPattern, parseAddViewData, processContentTests, processSplitUrlTests, registerHandler, reprocessContentTests, restoreOriginalElements, roundToTwo, sanitizeString, saveTestList, setCookie, setCountryCode, setGeoLocation, setReferrerData, setSessionItem, setupContentTestListeners, shouldShowTest, trackAddToCart, trackCartView, trackCheckoutCompleted, trackCheckoutStarted, trackPageView, trackProductView, trackRemoveFromCart, trackSearchSubmitted, trackSessionView, trackUniqueView, trackViews, updateCartAttributes, updateUrlWithTestParams, useElevateConfig, useExperiment, usePageViewTracking, uuidv4 };
|