Skip to content

Commit

Permalink
feat: MEG personalize and in-built storage support
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnilWingify authored and Varun Malhotra committed Nov 5, 2024
1 parent 4ddbbf0 commit 64146b9
Show file tree
Hide file tree
Showing 98 changed files with 10,728 additions and 439 deletions.
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# Changelog

All notable changes to this project will be documented in this file.

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

[0.1.0] - 2024-07-31
## [1.0.0] - 2024-11-11

### Added

- Added support for Personalise rules within `Mutually Exclusive Groups`.
- Settings cache: Cached settings will be used till it expires. Client can set the expiry time of cache.
- 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.
- Call backs added to avoid busy waiting for server call to complete.
- Changed variable access to method access for Flag - setIsEnabled & isEnabled

## [0.1.0] - 2024-07-31

### Added

- First release of VWO Feature Management and Experimentation capabilities.

```kotlin
Expand Down Expand Up @@ -53,9 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Log.d("Vwo", "vwoInitFailed: $message")
}
})

```
```

- **Error handling**

- Gracefully handle any kind of error - TypeError, NetworkError, etc.
- Gracefully handle any kind of error - TypeError, NetworkError, etc.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.FME"
tools:targetApi="31">
<!--Use android:usesCleartextTraffic="true" to test with http servers like gateways-->
<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -21,6 +22,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".JavaMainActivity"/>
</application>

</manifest>
168 changes: 168 additions & 0 deletions app/src/main/java/com/vwo/fme/JavaMainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2024 Wingify Software Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.vwo.fme;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.vwo.VWO;
import com.vwo.fme.databinding.ActivityMainBinding;
import com.vwo.interfaces.IVwoInitCallback;
import com.vwo.interfaces.IVwoListener;
import com.vwo.models.user.GetFlag;
import com.vwo.models.user.VWOContext;
import com.vwo.models.user.VWOInitOptions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JavaMainActivity extends AppCompatActivity {

TestApp prod = new TestApp(0,
"",
"flag-name",
"variable-name",
"event-name",
"attribute-name");

TestApp server = prod;
String SDK_KEY = server.getSdkKey();
int ACCOUNT_ID = server.getAccountId();

private VWO vwo;
private GetFlag featureFlag;
private VWOContext userContext;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

binding.tvName.setText("FME Java");

binding.btnInitSdk.setOnClickListener(view -> {
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey(SDK_KEY);
vwoInitOptions.setAccountId(ACCOUNT_ID);

Map<String, Object> loggerOptions = new HashMap<>();
loggerOptions.put("level", "TRACE");
vwoInitOptions.setLogger(loggerOptions);

VWO.init(vwoInitOptions, new IVwoInitCallback() {
@Override
public void vwoInitSuccess(@NonNull VWO vwo, @NonNull String message) {
Log.d("Flag", "vwoInitSuccess " + message);
JavaMainActivity.this.vwo = vwo;
}

@Override
public void vwoInitFailed(@NonNull String message) {
Log.d("Flag", "vwoInitFailed: " + message);
}
});
});
binding.btnGetFlag.setOnClickListener(v -> {
if (vwo != null) {
getFlag(vwo);
}
});

binding.btnGetVariable.setOnClickListener(v -> {
if (featureFlag != null) {
getVariable(featureFlag);
}
});

binding.btnTrack.setOnClickListener(v -> track());

binding.btnAttribute.setOnClickListener(v -> sendAttribute());
binding.btnJavaScreen.setVisibility(View.GONE);
}

private void getFlag(@NonNull VWO vwo) {
userContext = new VWOContext();
userContext.setId("unique_user_id");

Map<String, Object> customVariables = new HashMap<>();
customVariables.put("Username", "Swapnil");
customVariables.put("userType", "trial");
userContext.setCustomVariables(customVariables);

vwo.getFlag("feature-key", userContext, new IVwoListener() {
public void onSuccess(Object data) {
featureFlag = (GetFlag) data;
if (featureFlag != null) {
boolean isFeatureFlagEnabled = featureFlag.isEnabled();
Log.d("FME-App", "Received getFlag isFeatureFlagEnabled=" + isFeatureFlagEnabled);
}
}

public void onFailure(@NonNull String message) {
Log.d("FME-App", "getFlag " + message);
}
});
if (featureFlag == null)
return;
boolean isFeatureFlagEnabled = featureFlag.isEnabled();

Log.d("Flag", "isFeatureFlagEnabled=" + isFeatureFlagEnabled);
}

private void getVariable(@NonNull GetFlag featureFlag) {
boolean isFeatureFlagEnabled = featureFlag.isEnabled();
Log.d("Flag", "isFeatureFlagEnabled=" + isFeatureFlagEnabled);

if (isFeatureFlagEnabled) {
String variable1 = (String) featureFlag.getVariable("variable_key", "default-value1");

List<Map<String, Object>> getAllVariables = featureFlag.getVariables();
Log.d("Flag", "variable1=" + variable1 + " getAllVariables=" + getAllVariables);
} else {
Log.d("Flag", "Feature flag is disabled: " + featureFlag.isEnabled() + " " + featureFlag.getVariables());
}
}

private void track() {
if (userContext == null) return;

Map<String, Object> properties = new HashMap<>();
properties.put("cartvalue", 120);
properties.put("productCountInCart", 2);

// Track the event for the given event name, user context and properties
Map<String, Boolean> trackResponse = vwo.trackEvent("productViewed", userContext, properties);
Log.d("Flag", "track=" + trackResponse);
// Track the event for the given event name and user context
//Map<String, Boolean> trackResponse = vwo.trackEvent("vwoevent", userContext);
}

private void sendAttribute() {
if (vwo != null) {
vwo.setAttribute("userType", "paid", userContext);
vwo.setAttribute("attribute-name-float", 1.01, userContext);
vwo.setAttribute("attribute-name-boolean", true, userContext);
}
}
}
Loading

0 comments on commit 64146b9

Please sign in to comment.