vwo-fme-react-sdk 0.1.0
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 +80 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +352 -0
- package/dist/VWOContext.d.ts +24 -0
- package/dist/VWOProvider.d.ts +35 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +8 -0
- package/dist/logger/LogMessageBuilder.d.ts +63 -0
- package/dist/logger/Logger.d.ts +46 -0
- package/dist/logger/core/LogManager.d.ts +100 -0
- package/dist/logger/core/TransportManager.d.ts +80 -0
- package/dist/logger/enums/LogLevelEnum.d.ts +22 -0
- package/dist/logger/index.d.ts +17 -0
- package/dist/logger/transports/ConsoleTransport.d.ts +60 -0
- package/dist/services/loggerService.d.ts +35 -0
- package/dist/types/Common.d.ts +36 -0
- package/dist/useGetFlag.d.ts +21 -0
- package/dist/useGetFlagVariable.d.ts +29 -0
- package/dist/useSetAttribute.d.ts +20 -0
- package/dist/useTrackEvent.d.ts +21 -0
- package/dist/useVWOClient.d.ts +20 -0
- package/dist/utils/DataTypeUtil.d.ts +38 -0
- package/dist/vwo-fme-react-sdk.cjs.development.js +904 -0
- package/dist/vwo-fme-react-sdk.cjs.development.js.map +1 -0
- package/dist/vwo-fme-react-sdk.cjs.production.min.js +904 -0
- package/dist/vwo-fme-react-sdk.cjs.production.min.js.map +1 -0
- package/dist/vwo-fme-react-sdk.esm.js +886 -0
- package/dist/vwo-fme-react-sdk.esm.js.map +1 -0
- package/lib/VWOContext.ts +47 -0
- package/lib/VWOProvider.tsx +103 -0
- package/lib/index.ts +29 -0
- package/lib/logger/LogMessageBuilder.ts +99 -0
- package/lib/logger/Logger.ts +51 -0
- package/lib/logger/core/LogManager.ts +164 -0
- package/lib/logger/core/TransportManager.ts +142 -0
- package/lib/logger/enums/LogLevelEnum.ts +23 -0
- package/lib/logger/index.ts +18 -0
- package/lib/logger/transports/ConsoleTransport.ts +85 -0
- package/lib/services/LoggerService.ts +49 -0
- package/lib/types/Common.ts +42 -0
- package/lib/useGetFlag.ts +81 -0
- package/lib/useGetFlagVariable.ts +65 -0
- package/lib/useSetAttribute.ts +48 -0
- package/lib/useTrackEvent.ts +52 -0
- package/lib/useVWOClient.ts +41 -0
- package/lib/utils/DataTypeUtil.ts +48 -0
- package/package.json +84 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-02-13
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- The **VWO Feature Management and Experimentation SDK** (VWO FME React SDK) enables React.js developers to integrate feature flagging and experimentation into their applications. This SDK provides full control over feature rollout, A/B testing, and event tracking, allowing teams to manage features dynamically and gain insights into user behavior.
|
|
13
|
+
|
|
14
|
+
#### Basic Usage
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { VWOProvider } from 'vwo-fme-react-sdk';
|
|
19
|
+
|
|
20
|
+
const vwoConfig = {
|
|
21
|
+
sdkKey: '32-alpha-numeric-sdk-key', // Your VWO SDK Key
|
|
22
|
+
accountId: '123456', // Your VWO Account ID
|
|
23
|
+
logger: {
|
|
24
|
+
level: 'debug', // Optional log level for debugging
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const userContext = {
|
|
29
|
+
id: 'unique_user_id', // Required: Unique identifier for the user
|
|
30
|
+
customVariables: { age: 25, location: 'US' }, // Optional
|
|
31
|
+
userAgent:
|
|
32
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36', // Optional
|
|
33
|
+
ipAddress: '1.1.1.1', // Optional
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const App = () => (
|
|
37
|
+
<VWOProvider config={vwoConfig} context={userContext}>
|
|
38
|
+
<YourComponent />
|
|
39
|
+
</VWOProvider>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export default App;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Feature flag and variables Usage
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import React from 'react';
|
|
49
|
+
import { useGetFlag, useGetFlagVariable } from 'vwo-fme-react-sdk'; // Import hooks
|
|
50
|
+
|
|
51
|
+
const YourComponent = () => {
|
|
52
|
+
// Retrieve the flag using the feature key
|
|
53
|
+
const flag = useGetFlag('feature_key');
|
|
54
|
+
|
|
55
|
+
// Check if the flag is enabled
|
|
56
|
+
const isEnabled = flag?.isEnabled();
|
|
57
|
+
if (isEnabled) {
|
|
58
|
+
// Use the flag object returned by useGetFlag to retrieve a specific variable
|
|
59
|
+
// Replace 'variableKey' with the actual key for the variable you want to retrieve
|
|
60
|
+
const variableKey = 'variable_name'; // Replace with actual variable key
|
|
61
|
+
const variableValue = useGetFlagVariable(flag, variableKey, 'default_value');
|
|
62
|
+
|
|
63
|
+
// Display the feature flag variable value
|
|
64
|
+
return (
|
|
65
|
+
<div>
|
|
66
|
+
<p>Feature Flag Variable Value: {variableValue}</p>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Display a message if the feature is not enabled
|
|
72
|
+
return (
|
|
73
|
+
<div>
|
|
74
|
+
<p>Feature is not enabled!</p>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default YourComponent;
|
|
80
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Wingify Software Pvt. Ltd.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright 2025 Wingify Software Pvt. Ltd.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Wingify VWO FME React SDK
|
|
16
|
+
|
|
17
|
+
This product includes software developed at
|
|
18
|
+
Wingify Software Pvt. Ltd. (https://wingify.com/).
|
package/README.md
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
# VWO Feature Management and Experimentation SDK for React SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/vwo-fme-react-sdk)
|
|
4
|
+
[](http://www.apache.org/licenses/LICENSE-2.0)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The **VWO Feature Management and Experimentation SDK** (VWO FME React SDK) enables React.js developers to integrate feature flagging and experimentation into their applications. This SDK provides full control over feature rollout, A/B testing, and event tracking, allowing teams to manage features dynamically and gain insights into user behavior.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- **React 16.8+**
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install the SDK via [**npm**](https://npmjs.com/package/vwo-fme-react-sdk) or [**yarn**](https://classic.yarnpkg.com/en/package/vwo-fme-react-sdk):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# via npm
|
|
21
|
+
npm install vwo-fme-react-sdk --save
|
|
22
|
+
|
|
23
|
+
# via yarn
|
|
24
|
+
yarn add vwo-fme-react-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Basic Usage Example
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import React from 'react';
|
|
31
|
+
import { VWOProvider } from 'vwo-fme-react-sdk';
|
|
32
|
+
|
|
33
|
+
const vwoConfig = {
|
|
34
|
+
sdkKey: '32-alpha-numeric-sdk-key', // Your VWO SDK Key
|
|
35
|
+
accountId: '123456', // Your VWO Account ID
|
|
36
|
+
logger: {
|
|
37
|
+
level: 'debug', // Optional log level for debugging
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const userContext = {
|
|
42
|
+
id: 'unique_user_id', // Required: Unique identifier for the user
|
|
43
|
+
customVariables: { age: 25, location: 'US' }, // Optional
|
|
44
|
+
userAgent:
|
|
45
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36', // Optional
|
|
46
|
+
ipAddress: '1.1.1.1', // Optional
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const App = () => (
|
|
50
|
+
<VWOProvider config={vwoConfig} context={userContext}>
|
|
51
|
+
<YourComponent />
|
|
52
|
+
</VWOProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export default App;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Advanced Configuration Options
|
|
59
|
+
|
|
60
|
+
To customize the SDK further, additional parameters can be passed to the `VWOProvider` component. Here’s a table describing each option:
|
|
61
|
+
|
|
62
|
+
| **Parameter** | **Description** | **Required** | **Type** | **Example** |
|
|
63
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------- | ------------------------------- |
|
|
64
|
+
| `accountId` | VWO Account ID for authentication. | Yes | String | `'123456'` |
|
|
65
|
+
| `sdkKey` | SDK key corresponding to the specific environment to initialize the VWO SDK Client. You can get this key from VWO Application. | Yes | String | `'32-alpha-numeric-sdk-key'` |
|
|
66
|
+
| `pollInterval` | Time interval for fetching updates from VWO servers (in milliseconds). | No | Number | `60000` |
|
|
67
|
+
| `storage` | Custom storage connector for persisting user decisions and campaign data. | No | Object | See [Storage](#storage) section |
|
|
68
|
+
| `logger` | Toggle log levels for more insights or for debugging purposes. You can also customize your own transport in order to have better control over log messages. | No | Object | See [Logger](#logger) section |
|
|
69
|
+
|
|
70
|
+
Refer to the [official VWO documentation](https://developers.vwo.com/v2/docs/fme-react-initialization) for additional parameter details.
|
|
71
|
+
|
|
72
|
+
### User Context
|
|
73
|
+
|
|
74
|
+
The `context` object uniquely identifies users and is crucial for consistent feature rollouts. A typical `context` includes an `id` for identifying the user. It can also include other attributes that can be used for targeting and segmentation, such as `customVariables`, `userAgent` and `ipAddress`.
|
|
75
|
+
|
|
76
|
+
#### Parameters Table
|
|
77
|
+
|
|
78
|
+
The following table explains all the parameters in the `context` object:
|
|
79
|
+
|
|
80
|
+
| **Parameter** | **Description** | **Required** | **Type** | **Example** |
|
|
81
|
+
| ----------------- | -------------------------------------------------------------------------- | ------------ | -------- | --------------------------------- |
|
|
82
|
+
| `id` | Unique identifier for the user. | Yes | String | `'unique_user_id'` |
|
|
83
|
+
| `customVariables` | Custom attributes for targeting. | No | Object | `{ age: 25, location: 'US' }` |
|
|
84
|
+
| `userAgent` | User agent string for identifying the user's browser and operating system. | No | String | `'Mozilla/5.0 ... Safari/537.36'` |
|
|
85
|
+
| `ipAddress` | IP address of the user. | No | String | `'1.1.1.1'` |
|
|
86
|
+
|
|
87
|
+
#### Example
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
const userContext = {
|
|
91
|
+
id: 'unique_user_id',
|
|
92
|
+
customVariables: { age: 25, location: 'US' },
|
|
93
|
+
userAgent:
|
|
94
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
|
|
95
|
+
ipAddress: '1.1.1.1',
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Basic Feature Flagging
|
|
100
|
+
|
|
101
|
+
Feature Flags serve as the foundation for all testing, personalization, and rollout rules within FME.
|
|
102
|
+
To implement a feature flag, first use the `useGetFlag` hook to retrieve the flag configuration.
|
|
103
|
+
The `useGetFlag` hook provides a simple way to check if a feature is enabled for a specific user and access its variables. It returns a feature flag object that contains methods for checking the feature's status and retrieving any associated variables.
|
|
104
|
+
|
|
105
|
+
| Parameter | Description | Required | Type | Example |
|
|
106
|
+
| ------------ | ------------------------------------- | -------- | ------ | ---------------- |
|
|
107
|
+
| `featureKey` | Unique identifier of the feature flag | Yes | String | `'new_checkout'` |
|
|
108
|
+
|
|
109
|
+
Example usage:
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
import React from 'react';
|
|
113
|
+
import { useGetFlag, useGetFlagVariable } from 'vwo-fme-react-sdk'; // Import hooks
|
|
114
|
+
|
|
115
|
+
const YourComponent = () => {
|
|
116
|
+
// Retrieve the flag using the feature key
|
|
117
|
+
const flag = useGetFlag('feature_key');
|
|
118
|
+
|
|
119
|
+
// Check if the flag is enabled
|
|
120
|
+
const isEnabled = flag?.isEnabled();
|
|
121
|
+
if (isEnabled) {
|
|
122
|
+
// Use the flag object returned by useGetFlag to retrieve a specific variable
|
|
123
|
+
// Replace 'variableKey' with the actual key for the variable you want to retrieve
|
|
124
|
+
const variableKey = 'variable_name'; // Replace with actual variable key
|
|
125
|
+
const variableValue = useGetFlagVariable(flag, variableKey, 'default_value');
|
|
126
|
+
|
|
127
|
+
// Display the feature flag variable value
|
|
128
|
+
return (
|
|
129
|
+
<div>
|
|
130
|
+
<p>Feature Flag Variable Value: {variableValue}</p>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Display a message if the feature is not enabled
|
|
136
|
+
return (
|
|
137
|
+
<div>
|
|
138
|
+
<p>Feature is not enabled!</p>
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export default YourComponent;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Custom Event Tracking
|
|
147
|
+
|
|
148
|
+
Feature flags can be enhanced with connected metrics to track key performance indicators (KPIs) for your features. These metrics help measure the effectiveness of your testing rules by comparing control versus variation performance, and evaluate the impact of personalization and rollout campaigns. Use the `useTrackEvent` hook to track custom events like conversions, user interactions, and other important metrics:
|
|
149
|
+
|
|
150
|
+
| Parameter | Description | Required | Type | Example |
|
|
151
|
+
| ----------------- | -------------------------------------------------------- | -------- | ------ | ---------------------- |
|
|
152
|
+
| `eventName` | Name of the event you want to track | Yes | String | `'purchase_completed'` |
|
|
153
|
+
| `eventProperties` | Additional properties/metadata associated with the event | No | Object | `{ amount: 49.99 }` |
|
|
154
|
+
|
|
155
|
+
Example usage:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import { useTrackEvent } from 'vwo-fme-react-sdk'; // Import the hook
|
|
159
|
+
|
|
160
|
+
const YourComponent = () => {
|
|
161
|
+
// Track an event when a button is clicked, the second parameter for useTrackEvent is optional.
|
|
162
|
+
useTrackEvent('button_click', { userType: 'premium' });
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export default YourComponent;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
See [Tracking Conversions](https://developers.vwo.com/v2/docs/fme-react-metrics-tracking#usage) documentation for more information.
|
|
169
|
+
|
|
170
|
+
### Pushing Attributes
|
|
171
|
+
|
|
172
|
+
User attributes provide rich contextual information about users, enabling powerful personalization. The `useSetAttribute` hook provides a simple way to associate these attributes with users in VWO for advanced segmentation. Here's what you need to know about the method parameters:
|
|
173
|
+
|
|
174
|
+
| Parameter | Description | Required | Type | Example |
|
|
175
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------- | ------ | ----------------------------- |
|
|
176
|
+
| `attributeMap` | A key-value map of attributes to set for the user. The keys are attribute names and values are the corresponding attribute values. | Yes | Object | `{ age: 25, location: 'US' }` |
|
|
177
|
+
|
|
178
|
+
Example usage:
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
import { useSetAttribute } from 'vwo-fme-react-sdk'; // Import the hook
|
|
182
|
+
|
|
183
|
+
const YourComponent = () => {
|
|
184
|
+
// Set attributes for the user
|
|
185
|
+
useSetAttribute({ age: 25, location: 'US' });
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export default YourComponent;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
See [Pushing Attributes](https://developers.vwo.com/v2/docs/fme-react-attributes#usage) documentation for additional information.
|
|
192
|
+
|
|
193
|
+
### Polling Interval Adjustment
|
|
194
|
+
|
|
195
|
+
The `pollInterval` is an optional parameter that allows the SDK to automatically fetch and update settings from the VWO server at specified intervals. Setting this parameter ensures your application always uses the latest configuration.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
const vwoConfig = {
|
|
199
|
+
sdkKey: '32-alpha-numeric-sdk-key', // Your VWO SDK Key
|
|
200
|
+
accountId: '123456', // Your VWO Account ID
|
|
201
|
+
pollInterval: 60000, // Time interval for fetching updates from VWO servers (in milliseconds)
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const App = () => (
|
|
205
|
+
<VWOProvider config={vwoConfig} context={{ id: 'unique_user_id' }}>
|
|
206
|
+
<YourComponent />
|
|
207
|
+
</VWOProvider>
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Storage
|
|
212
|
+
|
|
213
|
+
The SDK operates in a stateless mode by default, meaning each `useGetFlag` hook triggers a fresh evaluation of the flag against the current user context.
|
|
214
|
+
|
|
215
|
+
To optimize performance and maintain consistency, you can implement a custom storage mechanism by passing a `storage` parameter during initialization. This allows you to persist feature flag decisions in your preferred database system (like Redis, MongoDB, or any other data store).
|
|
216
|
+
|
|
217
|
+
Key benefits of implementing storage:
|
|
218
|
+
|
|
219
|
+
- Improved performance by caching decisions
|
|
220
|
+
- Consistent user experience across sessions
|
|
221
|
+
- Reduced load on your application
|
|
222
|
+
|
|
223
|
+
The storage mechanism ensures that once a decision is made for a user, it remains consistent even if campaign settings are modified in the VWO Application. This is particularly useful for maintaining a stable user experience during A/B tests and feature rollouts.
|
|
224
|
+
|
|
225
|
+
```javascript
|
|
226
|
+
import { VWOProvider } from 'vwo-fme-react-sdk';
|
|
227
|
+
|
|
228
|
+
class StorageConnector extends StorageConnector {
|
|
229
|
+
constructor() {
|
|
230
|
+
super();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Get data from storage
|
|
235
|
+
* @param {string} featureKey
|
|
236
|
+
* @param {string} userId
|
|
237
|
+
* @returns {Promise<any>}
|
|
238
|
+
*/
|
|
239
|
+
async get(featureKey, userId) {
|
|
240
|
+
// return await data (based on featureKey and userId)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set data in storage
|
|
245
|
+
* @param {object} data
|
|
246
|
+
*/
|
|
247
|
+
async set(data) {
|
|
248
|
+
// Set data corresponding to a featureKey and user ID
|
|
249
|
+
// Use data.featureKey and data.userId to store the above data for a specific feature and a user
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const vwoConfig = {
|
|
254
|
+
sdkKey: '32-alpha-numeric-sdk-key', // Your VWO SDK Key
|
|
255
|
+
accountId: '123456', // Your VWO Account ID
|
|
256
|
+
logger: {
|
|
257
|
+
level: 'debug', // Optional log level for debugging
|
|
258
|
+
},
|
|
259
|
+
storage: StorageConnector,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const App = () => (
|
|
263
|
+
<VWOProvider config={vwoConfig} context={{ id: 'unique_user_id' }}>
|
|
264
|
+
<YourComponent />
|
|
265
|
+
</VWOProvider>
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
export default App;
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Logger
|
|
272
|
+
|
|
273
|
+
VWO by default logs all `ERROR` level messages to your server console.
|
|
274
|
+
To gain more control over VWO's logging behaviour, you can use the `logger` parameter in the `init` configuration.
|
|
275
|
+
|
|
276
|
+
| **Parameter** | **Description** | **Required** | **Type** | **Example** |
|
|
277
|
+
| ------------- | -------------------------------------- | ------------ | -------- | --------------------- |
|
|
278
|
+
| `level` | Log level to control verbosity of logs | Yes | String | `DEBUG` |
|
|
279
|
+
| `prefix` | Custom prefix for log messages | No | String | `'CUSTOM LOG PREFIX'` |
|
|
280
|
+
|
|
281
|
+
#### Example 1: Set log level to control verbosity of logs
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
const options = {
|
|
285
|
+
sdkKey: '32-alpha-numeric-sdk-key', // SDK Key
|
|
286
|
+
accountId: '123456', // VWO Account ID
|
|
287
|
+
logger: {
|
|
288
|
+
level: 'debug',
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const App = () => (
|
|
293
|
+
<VWOProvider config={vwoConfig} context={{ id: 'unique_user_id' }}>
|
|
294
|
+
<YourComponent />
|
|
295
|
+
</VWOProvider>
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
export default App;
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### Example 2: Add custom prefix to log messages for easier identification
|
|
302
|
+
|
|
303
|
+
```javascript
|
|
304
|
+
const options = {
|
|
305
|
+
sdkKey: '32-alpha-numeric-sdk-key', // SDK Key
|
|
306
|
+
accountId: '123456', // VWO Account ID
|
|
307
|
+
logger: {
|
|
308
|
+
level: 'debug',
|
|
309
|
+
prefix: 'CUSTOM LOG PREFIX', // custom logger prefix
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const App = () => (
|
|
314
|
+
<VWOProvider config={vwoConfig} context={{ id: 'unique_user_id' }}>
|
|
315
|
+
<YourComponent />
|
|
316
|
+
</VWOProvider>
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
export default App;
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Version History
|
|
323
|
+
|
|
324
|
+
The version history tracks changes, improvements, and bug fixes in each version. For a full history, see the [CHANGELOG.md](https://github.com/wingify/vwo-fme-react-sdk/blob/master/CHANGELOG.md).
|
|
325
|
+
|
|
326
|
+
## Development and Testing
|
|
327
|
+
|
|
328
|
+
### Install Dependencies and Bootstrap Git Hooks
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
yarn install
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Compile TypeScript to JavaScript
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
yarn build
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Contributing
|
|
341
|
+
|
|
342
|
+
We welcome contributions to improve this SDK! Please read our [contributing guidelines](https://github.com/wingify/vwo-fme-react-sdk/blob/master/CONTRIBUTING.md) before submitting a PR.
|
|
343
|
+
|
|
344
|
+
## Code of Conduct
|
|
345
|
+
|
|
346
|
+
Our [Code of Conduct](https://github.com/wingify/vwo-fme-react-sdk/blob/master/CODE_OF_CONDUCT.md) outlines expectations for all contributors and maintainers.
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
[Apache License, Version 2.0](https://github.com/wingify/vwo-fme-react-sdk/blob/master/LICENSE)
|
|
351
|
+
|
|
352
|
+
Copyright 2025 Wingify Software Pvt. Ltd.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Wingify Software Pvt. Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Context for VWO SDK
|
|
18
|
+
*/
|
|
19
|
+
export declare const VWOContext: any;
|
|
20
|
+
/**
|
|
21
|
+
* Hook to use the VWO context
|
|
22
|
+
* @returns VWO context
|
|
23
|
+
*/
|
|
24
|
+
export declare const useVWOContext: () => any;
|