@dotcms/experiments 0.0.1-alpha.13 → 0.0.1-alpha.15
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.esm.js +4414 -4264
- package/package.json +2 -2
- package/src/index.d.ts +1 -3
- package/src/lib/components/DotExperimentHandlingComponent.d.ts +21 -0
- package/src/lib/components/withExperiments.d.ts +20 -0
- package/src/lib/contexts/DotExperimentsContext.d.ts +1 -0
- package/src/lib/dot-experiments.d.ts +12 -2
- package/src/lib/hooks/useExperimentVariant.d.ts +21 -0
- package/src/lib/shared/mocks/mock.d.ts +2 -1
- package/src/lib/shared/models.d.ts +8 -0
- package/src/lib/shared/parser/parser.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/experiments",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.15",
|
|
4
4
|
"description": "Official JavaScript library to use Experiments with DotCMS.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": ">=18",
|
|
27
27
|
"react-dom": ">=18",
|
|
28
|
-
"@dotcms/client": "0.0.1-alpha.
|
|
28
|
+
"@dotcms/client": "0.0.1-alpha.14"
|
|
29
29
|
},
|
|
30
30
|
"module": "./index.esm.js",
|
|
31
31
|
"type": "module",
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DotcmsPageProps } from '@dotcms/react';
|
|
3
|
+
interface ExperimentHandlingProps extends DotcmsPageProps {
|
|
4
|
+
WrappedComponent: React.ComponentType<DotcmsPageProps>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A React functional component that conditionally renders a WrappedComponent based on the
|
|
8
|
+
* experiment variant state. It uses the `useExperimentVariant` hook to determine if there's a
|
|
9
|
+
* variant mismatch. If the current variant does not match the assigned variant, it temporarily
|
|
10
|
+
* hides the WrappedComponent by rendering it with `visibility: hidden`. Once the correct variant
|
|
11
|
+
* is confirmed, it renders the WrappedComponent normally.
|
|
12
|
+
*
|
|
13
|
+
* @param {React.ComponentType<DotcmsPageProps>} WrappedComponent - The React component that will be
|
|
14
|
+
* conditionally rendered based on the experiment variant.
|
|
15
|
+
* @param {DotcmsPageProps} props - Props expected by the WrappedComponent, along with any additional
|
|
16
|
+
* props that extend from DotcmsPageProps.
|
|
17
|
+
* @returns {React.ReactElement} A React element that either renders the WrappedComponent hidden or visible
|
|
18
|
+
* based on the experiment variant.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DotExperimentHandlingComponent: React.FC<ExperimentHandlingProps>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { DotcmsPageProps } from '@dotcms/react';
|
|
3
|
+
import { DotExperimentConfig } from '../shared/models';
|
|
4
|
+
export interface PageProviderProps {
|
|
5
|
+
readonly entity: any;
|
|
6
|
+
readonly children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a given component with experiment handling capabilities using the 'useExperimentVariant' hook.
|
|
10
|
+
* This HOC checks if the entity's assigned experiment variant differs from the currently displayed variant.
|
|
11
|
+
* If they differ, the content is hidden until the correct variant is displayed. Once the assigned variant
|
|
12
|
+
* matches the displayed variant, the content of the WrappedComponent is shown.
|
|
13
|
+
*
|
|
14
|
+
* @param {React.ComponentType<DotcmsPageProps>} WrappedComponent - The component to be enhanced.
|
|
15
|
+
* @param {DotExperimentConfig} config - Configuration for experiment handling, including any necessary
|
|
16
|
+
* redirection functions or other settings.
|
|
17
|
+
* @returns {React.FunctionComponent<DotcmsPageProps>} A component that wraps the original component,
|
|
18
|
+
* adding experiment handling based on the specified configuration.
|
|
19
|
+
*/
|
|
20
|
+
export declare const withExperiments: (WrappedComponent: React.ComponentType<DotcmsPageProps>, config: DotExperimentConfig) => (props: DotcmsPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DotExperimentConfig, Experiment, Variant } from
|
|
1
|
+
import { DotExperimentConfig, Experiment, Variant } from "./shared/models";
|
|
2
2
|
/**
|
|
3
3
|
* `DotExperiments` is a Typescript class to handles all operations related to fetching, storing, parsing, and navigating
|
|
4
4
|
* data for Experiments (A/B Testing).
|
|
@@ -197,13 +197,23 @@ export declare class DotExperiments {
|
|
|
197
197
|
*/
|
|
198
198
|
private initialize;
|
|
199
199
|
/**
|
|
200
|
-
* Fetches experiments from the server.
|
|
200
|
+
* Fetches experiments from the server and merge if not ended the excluded requested.
|
|
201
201
|
*
|
|
202
202
|
* @private
|
|
203
203
|
* @returns {Promise<AssignedExperiments>} - The entity object returned from the server.
|
|
204
204
|
* @throws {Error} - If an HTTP error occurs or an error occurs during the fetch request.
|
|
205
205
|
*/
|
|
206
206
|
private getExperimentsFromServer;
|
|
207
|
+
/**
|
|
208
|
+
* Filters out experiments that are not yet ended from already assigned.
|
|
209
|
+
*
|
|
210
|
+
* @param {Array} excludedExperimentIdsEnded - The IDs of experiments to be excluded because they have ended.
|
|
211
|
+
*
|
|
212
|
+
* @return {Array} Experiments that are not in the list of those that have ended.
|
|
213
|
+
*
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
private getExperimentsNotEndedFromAlreadyAssigned;
|
|
207
217
|
/**
|
|
208
218
|
* This method is responsible for retrieving and persisting experiment data from the server to the local indexDB database.
|
|
209
219
|
*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React Hook that determines whether to wait for the correct variant in an A/B testing scenario.
|
|
3
|
+
* This is used to avoid flickering - showing the original content before redirecting to the assigned variant.
|
|
4
|
+
*
|
|
5
|
+
* The hook uses the running experiment id and viewAs (containing variantId) from the provided data.
|
|
6
|
+
* It then works with the DotExperimentsContext to synchronize between the assigned variant and the one requested.
|
|
7
|
+
* If the hook is executed inside an editor or if no running experiment id is provided, it immediately signals not to wait for the variant.
|
|
8
|
+
* Similarly, if the assigned variant matches the requested one, it signals not to wait for the variant.
|
|
9
|
+
* By default, the hook signals to wait for the variant.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} data - An object containing the runningExperimentId and viewAs (containing variantId).
|
|
12
|
+
* @returns {Object} An object with a function `shouldWaitForVariant` that, when called, returns `true` if it should wait for the correct variant, `false` otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useExperimentVariant: (data: {
|
|
15
|
+
runningExperimentId?: string;
|
|
16
|
+
viewAs: {
|
|
17
|
+
variantId: string;
|
|
18
|
+
};
|
|
19
|
+
}) => {
|
|
20
|
+
shouldWaitForVariant: boolean;
|
|
21
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Experiment, ExperimentEvent, IsUserIncludedApiResponse } from
|
|
1
|
+
import { Experiment, ExperimentEvent, IsUserIncludedApiResponse } from "../models";
|
|
2
2
|
/**
|
|
3
3
|
* Represents the response object for the IsUserIncluded API.
|
|
4
4
|
* @typedef {Object} IsUserIncludedResponse
|
|
@@ -9,6 +9,7 @@ import { Experiment, ExperimentEvent, IsUserIncludedApiResponse } from '../model
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const IsUserIncludedResponse: IsUserIncludedApiResponse;
|
|
11
11
|
export declare const NewIsUserIncludedResponse: IsUserIncludedApiResponse;
|
|
12
|
+
export declare const After15DaysIsUserIncludedResponse: IsUserIncludedApiResponse;
|
|
12
13
|
export declare const MOCK_CURRENT_TIMESTAMP = 1704096000000;
|
|
13
14
|
export declare const TIME_15_DAYS_MILLISECONDS: number;
|
|
14
15
|
export declare const TIME_5_DAYS_MILLISECONDS: number;
|
|
@@ -128,7 +128,15 @@ export interface AssignedExperiments {
|
|
|
128
128
|
* The ids of the experiments included in the assignment.
|
|
129
129
|
*/
|
|
130
130
|
includedExperimentIds: string[];
|
|
131
|
+
/**
|
|
132
|
+
* The ids of the experiments that are excluded in the request and have ended.
|
|
133
|
+
*/
|
|
134
|
+
excludedExperimentIdsEnded: string[];
|
|
131
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Represents the response from the backend when fetching an experiment.
|
|
138
|
+
*/
|
|
139
|
+
export type FetchExperiments = Pick<AssignedExperiments, 'excludedExperimentIdsEnded' | 'experiments'>;
|
|
132
140
|
/**
|
|
133
141
|
* Represents the response from backend holding information about running experiments and variant assignment.
|
|
134
142
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Experiment, ExperimentParsed } from
|
|
1
|
+
import { Experiment, ExperimentParsed, FetchExperiments } from "../models";
|
|
2
2
|
/**
|
|
3
3
|
* This arrow function parses a given set of assigned experiments for analytics.
|
|
4
4
|
*
|
|
@@ -44,7 +44,7 @@ export declare const verifyRegex: (regexToCheck: string | null, href: string) =>
|
|
|
44
44
|
*
|
|
45
45
|
* There could be scenarios where none of these conditions are met, in that case, dataToStorage will be the default empty object.
|
|
46
46
|
*/
|
|
47
|
-
export declare const parseData: (fetchExperiments:
|
|
47
|
+
export declare const parseData: (fetchExperiments: FetchExperiments, storedExperiments: Experiment[] | undefined) => Experiment[];
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the array of experiment IDs from the given AssignedExperiments..
|
|
50
50
|
*
|