Skip to content

Commit 64146b9

Browse files
swapnilWingifyVarun Malhotra
authored andcommitted
feat: MEG personalize and in-built storage support
1 parent 4ddbbf0 commit 64146b9

File tree

98 files changed

+10728
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+10728
-439
lines changed

CHANGELOG.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

7-
[0.1.0] - 2024-07-31
8+
## [1.0.0] - 2024-11-11
89

910
### Added
11+
12+
- Added support for Personalise rules within `Mutually Exclusive Groups`.
13+
- Settings cache: Cached settings will be used till it expires. Client can set the expiry time of cache.
14+
- Storage support: Built-in local storage will be used by default if client doesn't provide their own. Client’s storage will be used if it is provided.
15+
- Call backs added to avoid busy waiting for server call to complete.
16+
- Changed variable access to method access for Flag - setIsEnabled & isEnabled
17+
18+
## [0.1.0] - 2024-07-31
19+
20+
### Added
21+
1022
- First release of VWO Feature Management and Experimentation capabilities.
1123

1224
```kotlin
@@ -53,9 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5365
Log.d("Vwo", "vwoInitFailed: $message")
5466
}
5567
})
56-
57-
```
68+
```
5869

5970
- **Error handling**
6071

61-
- Gracefully handle any kind of error - TypeError, NetworkError, etc.
72+
- Gracefully handle any kind of error - TypeError, NetworkError, etc.

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
android:supportsRtl="true"
1313
android:theme="@style/Theme.FME"
1414
tools:targetApi="31">
15+
<!--Use android:usesCleartextTraffic="true" to test with http servers like gateways-->
1516
<activity
1617
android:name=".MainActivity"
1718
android:exported="true">
@@ -21,6 +22,8 @@
2122
<category android:name="android.intent.category.LAUNCHER" />
2223
</intent-filter>
2324
</activity>
25+
26+
<activity android:name=".JavaMainActivity"/>
2427
</application>
2528

2629
</manifest>
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright (c) 2024 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+
18+
package com.vwo.fme;
19+
20+
import android.os.Bundle;
21+
import android.util.Log;
22+
import android.view.View;
23+
24+
import androidx.annotation.NonNull;
25+
import androidx.appcompat.app.AppCompatActivity;
26+
27+
import com.vwo.VWO;
28+
import com.vwo.fme.databinding.ActivityMainBinding;
29+
import com.vwo.interfaces.IVwoInitCallback;
30+
import com.vwo.interfaces.IVwoListener;
31+
import com.vwo.models.user.GetFlag;
32+
import com.vwo.models.user.VWOContext;
33+
import com.vwo.models.user.VWOInitOptions;
34+
35+
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
39+
public class JavaMainActivity extends AppCompatActivity {
40+
41+
TestApp prod = new TestApp(0,
42+
"",
43+
"flag-name",
44+
"variable-name",
45+
"event-name",
46+
"attribute-name");
47+
48+
TestApp server = prod;
49+
String SDK_KEY = server.getSdkKey();
50+
int ACCOUNT_ID = server.getAccountId();
51+
52+
private VWO vwo;
53+
private GetFlag featureFlag;
54+
private VWOContext userContext;
55+
56+
@Override
57+
protected void onCreate(Bundle savedInstanceState) {
58+
super.onCreate(savedInstanceState);
59+
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
60+
setContentView(binding.getRoot());
61+
62+
binding.tvName.setText("FME Java");
63+
64+
binding.btnInitSdk.setOnClickListener(view -> {
65+
VWOInitOptions vwoInitOptions = new VWOInitOptions();
66+
vwoInitOptions.setSdkKey(SDK_KEY);
67+
vwoInitOptions.setAccountId(ACCOUNT_ID);
68+
69+
Map<String, Object> loggerOptions = new HashMap<>();
70+
loggerOptions.put("level", "TRACE");
71+
vwoInitOptions.setLogger(loggerOptions);
72+
73+
VWO.init(vwoInitOptions, new IVwoInitCallback() {
74+
@Override
75+
public void vwoInitSuccess(@NonNull VWO vwo, @NonNull String message) {
76+
Log.d("Flag", "vwoInitSuccess " + message);
77+
JavaMainActivity.this.vwo = vwo;
78+
}
79+
80+
@Override
81+
public void vwoInitFailed(@NonNull String message) {
82+
Log.d("Flag", "vwoInitFailed: " + message);
83+
}
84+
});
85+
});
86+
binding.btnGetFlag.setOnClickListener(v -> {
87+
if (vwo != null) {
88+
getFlag(vwo);
89+
}
90+
});
91+
92+
binding.btnGetVariable.setOnClickListener(v -> {
93+
if (featureFlag != null) {
94+
getVariable(featureFlag);
95+
}
96+
});
97+
98+
binding.btnTrack.setOnClickListener(v -> track());
99+
100+
binding.btnAttribute.setOnClickListener(v -> sendAttribute());
101+
binding.btnJavaScreen.setVisibility(View.GONE);
102+
}
103+
104+
private void getFlag(@NonNull VWO vwo) {
105+
userContext = new VWOContext();
106+
userContext.setId("unique_user_id");
107+
108+
Map<String, Object> customVariables = new HashMap<>();
109+
customVariables.put("Username", "Swapnil");
110+
customVariables.put("userType", "trial");
111+
userContext.setCustomVariables(customVariables);
112+
113+
vwo.getFlag("feature-key", userContext, new IVwoListener() {
114+
public void onSuccess(Object data) {
115+
featureFlag = (GetFlag) data;
116+
if (featureFlag != null) {
117+
boolean isFeatureFlagEnabled = featureFlag.isEnabled();
118+
Log.d("FME-App", "Received getFlag isFeatureFlagEnabled=" + isFeatureFlagEnabled);
119+
}
120+
}
121+
122+
public void onFailure(@NonNull String message) {
123+
Log.d("FME-App", "getFlag " + message);
124+
}
125+
});
126+
if (featureFlag == null)
127+
return;
128+
boolean isFeatureFlagEnabled = featureFlag.isEnabled();
129+
130+
Log.d("Flag", "isFeatureFlagEnabled=" + isFeatureFlagEnabled);
131+
}
132+
133+
private void getVariable(@NonNull GetFlag featureFlag) {
134+
boolean isFeatureFlagEnabled = featureFlag.isEnabled();
135+
Log.d("Flag", "isFeatureFlagEnabled=" + isFeatureFlagEnabled);
136+
137+
if (isFeatureFlagEnabled) {
138+
String variable1 = (String) featureFlag.getVariable("variable_key", "default-value1");
139+
140+
List<Map<String, Object>> getAllVariables = featureFlag.getVariables();
141+
Log.d("Flag", "variable1=" + variable1 + " getAllVariables=" + getAllVariables);
142+
} else {
143+
Log.d("Flag", "Feature flag is disabled: " + featureFlag.isEnabled() + " " + featureFlag.getVariables());
144+
}
145+
}
146+
147+
private void track() {
148+
if (userContext == null) return;
149+
150+
Map<String, Object> properties = new HashMap<>();
151+
properties.put("cartvalue", 120);
152+
properties.put("productCountInCart", 2);
153+
154+
// Track the event for the given event name, user context and properties
155+
Map<String, Boolean> trackResponse = vwo.trackEvent("productViewed", userContext, properties);
156+
Log.d("Flag", "track=" + trackResponse);
157+
// Track the event for the given event name and user context
158+
//Map<String, Boolean> trackResponse = vwo.trackEvent("vwoevent", userContext);
159+
}
160+
161+
private void sendAttribute() {
162+
if (vwo != null) {
163+
vwo.setAttribute("userType", "paid", userContext);
164+
vwo.setAttribute("attribute-name-float", 1.01, userContext);
165+
vwo.setAttribute("attribute-name-boolean", true, userContext);
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)