Android
CustomerGlu SDK for Android enables you to open CustomerGlu campaigns in your app, add Dynamic Entry Points for the campaigns, Paint rich In-app Nudges, Send user events and a lot more...

Pre-Requisites

CustomerGlu Android SDK supports API 21 and above. Please ensure the minSDKVersion in the app's build.gradle file reflects the same.

​
πŸ’‘
Note

If Proguard is enabled in the app, please add the following rule in Proguard Rules file to ensure smooth working of CustomerGlu SDK.
1
-keep class com.customerglu.sdk.Modal.*{*;}
Copied!

Permissions

Add the following permissions to the AndroidManifest.xml file
1
<uses-permission android:name="android.permission.INTERNET" />
2
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Copied!

Installation

Add the following dependency to the app's build.gradle file:
1
dependencies{
2
implementation 'com.github.customerglu:CG-SDK-Android:v2.0.1'
3
}
Copied!
If targetSdkVersion <=30, add the below code snippet in project level build.gradle file:
1
allprojects {
2
repositories {
3
...
4
maven { url "https://jitpack.io"}
5
}
6
}
Copied!
If targetSdkVersion >=31, add the below code snippet in settings.gradle file:
1
dependencyResolutionManagement {
2
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3
repositories {
4
...
5
maven { url 'https://jitpack.io' }
6
​
7
}
8
}
Copied!

Initialise SDK

​
⚠
WriteKey - Mandatory (WriteKey/API Key is provided by CustomerGlu)
Add your WriteKey/API Key in meta-data of the AndroidManifest.xml file like this:
1
<meta-data android:name="CUSTOMERGLU_WRITE_KEY" android:value="YOUR_WRITE_KEY" />
2
<!-- only value should be changed -->
Copied!
Define the global instance of CustomerGlu SDK by initializing the following in the onCreate() method of your application class:
1
public CustomerGlu customerGlu;
2
customerGlu = CustomerGlu.getInstance();
Copied!

Register User (Mandatory)

Use the given function to register a user with CustomerGlu:
1
customerGlu.registerDevice(this,userData,true,new DataListner() {
2
//this method registers the user
3
@Override
4
public void onSuccess(RegisterModal registerModal) {
5
Toast.makeText(getApplicationContext(), "Registered", Toast.LENGTH_SHORT).show();
6
}
7
​
8
@Override
9
public void onFail(String message) {
10
Toast.makeText(getApplicationContext(), ""+message, Toast.LENGTH_SHORT).show();
11
}
12
}
Copied!
​
πŸ’‘
Note: The Register function is also used to update the user attributes

Function Parameters:

  1. 1.
    Context: this/getApplicationContext()
  2. 2.
    userData: A HashMap that holds user information
Sample UserData object
1
Map<String,Object> userData = new HashMap<>();
2
String user_id="testUser_1";
3
String fcmToken="FCM_TOKEN_OF_DEVICE";
4
userData.put("userId",user_id); // Mandatory:any identifier to uniquely identify a user of your platform
5
userdata.put("firebaseToken",fcmToken); // for enabling Firebase Notifications
6
Map<String,String> customAttributes = new HashMap<>();
7
// any custom key-value pairs, which may be used for targeting can be sent as customAttributes
8
// segments can be created by applying filters on these customAttributes
9
// campaigns can be launched on specific segments
10
customAttributes.put("orderCount",5);
11
customAttributes.put("age",21);
12
customAttributes.put("city","Mumbai");
13
userdata.put("customAttributes",customAttributes);
14
Map<String,String> profile = new HashMap<>();
15
profile.put("firstName","jane");
16
userdata.put("profile",profile);
Copied!
​
πŸ’‘
Note: You can check out the complete userData object payload here.
3. loadcampaigns (Boolean) - It accepts a boolean value- if "true", then a loadCampaigns call is made during registration, ensuring the latest campaigns, the user is eligible for, are pre-fetched (improves load times).

Clear Data on Logout (Mandatory)

Use the given function when the user logs out, to clear CustomerGlu SDK cached data like user_id, token etc.
1
customerGlu.clearGluData(getApplicationContext());
Copied!

Handling Webview Events

Enable Closing of Webview on UI button click
This function will enable closing the CustomerGlu webviews on clicking the close button on the UI:
1
customerGlu.closeWebviewOnDeeplinkEvent(true);
Copied!
Enable Analytics Event
If click analytics are to be captured directly via the app, you can enable the analytics events by using the given function:
1
customerGlu.enableAnalyticsEvent(true);
Copied!
Set up Broadcast Receiver
Register a broadcast receiver for listening to the events triggered by the webview to handle:
  1. 1.
    Deeplink redirection: Redirect to a given screen on click of buttons from CustomerGlu UIs Example: Clicking on "Go To Cart" should redirect to the Cart Screen
  2. 2.
    Analytics Events: Send click analytics events on CG UI directly from the app to your servers/CDP Platform Example: coupon code copied event
For handling Deeplink or Analytics events triggered by the webview, you need to register a broadcast receiver:
1
BroadcastReceiver mMessageReceiver;
2
3
mMessageReceiver = new BroadcastReceiver() {
4
@Override
5
public void onReceive(Context context, Intent intent) {
6
try {
7
​
8
if(intent.getAction().equalsIgnoreCase("CUSTOMERGLU_DEEPLINK_EVENT"))
9
{
10
String data = intent.getStringExtra("data");
11
JSONObject jsonObject = new JSONObject(data);
12
String message = jsonObject.getString("deepLink");
13
// Add the logic to redirect to appropriate page
14
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
15
}
16
/* If you want to listen analytics event */
17
if(intent.getAction().equalsIgnoreCase("CUSTOMERGLU_ANALYTICS_EVENT"))
18
{
19
​
20
String data = intent.getStringExtra("data");
21
JSONObject jsonObject = new JSONObject(data);
22
Toast.makeText(getApplicationContext(), jsonObject.toString(), Toast.LENGTH_LONG).show();
23
//This Event can be forwarded to your Servers/CDP tool
24
}
25
}
26
catch (Exception e)
27
{
28
System.out.println(e);
29
}
30
}
31
​
32
};
33
registerReceiver(mMessageReceiver,new IntentFilter("CUSTOMERGLU_DEEPLINK_EVENT"));
34
/* If you want to listen analytics event register the below reciever*/
35
registerReceiver(mMessageReceiver,new IntentFilter("CUSTOMERGLU_ANALYTICS_EVENT"));
36
​
37
​
Copied!
​
πŸ’‘
Note: Do not unregister the broadcast receiver in the app lifecycle.
​

Functionality

Open Wallet

Use the given function to open the wallet screen powered by CustomerGlu:
1
customerGlu.openWallet(getApplicationContext());
Copied!

​

Load Campaign By Id

Use this function to directly open a specific campaign, if the campaignId/tag is known:
1
customerGlu.loadCampaignById(getApplicationContext(),"CAMPAIGN_ID/TAG");
Copied!
  1. 1.
    CampaignId : Unique Identifier assigned to each campaign by default, can be copied from the dashboard.
2. Tag: An optional tag can be assigned to each campaign from the dashboard
​
πŸ’‘
Note: If the value of campaignId/tag provided is empty/invalid, wallet will be opened by default

Entry Points

The following entry points are supported by CustomerGlu SDK:
  • Banners
​
​
  • Floating Buttons/Launchers
​
  • Popups
​

​

Enable Entry Points

Use the given function to enable Entry Points in the app (needs to be called on every app launch):
1
customerGlu.enableEntryPoints(getApplicationContext(), true);
Copied!

Enable SDK Debugging Mode

Debugging mode enables logging and passes the app screen names to CustomerGlu so the list of all available screens of the app is available already on the entry point configuration sections on the dashboard.
​
⚠
Please make sure to disable debugging mode in Release/Production build.
​
The given function can be used to enable SDK debugging mode:
1
customerGlu.gluSDKDebuggingMode(getApplicationContext(), true);
Copied!

Setting up Banners

Add the following banner component, wherever a banner might be needed, in the Activity’s layout file:
​
⚠
Please make sure the component is added to all the possible places where banners might be needed, as an app release will be required to change the same. The banners will only appear when configured on the dashboard to be visible.
1
<com.customerglu.sdk.Banners.Banner
2
android:layout_width="wrap_content"
3
android:layout_height="wrap_content"
4
android:id="@+id/someUniqueIdentifier"/> //same id should be configured on the dashboard
Copied!
​
πŸ’‘
Note : The id is mandatory and the exact same id needs to be configured on the dashboard as the bannerId in the entry point configuration section. Please follow a semantic nomenclature like screenName_banner_1 for the ids for ease of configuration on the dashboard.
Banner Loaded Callback (optional)
The banner component will be hidden automatically in cases like the banner being disabled, user not eligible to see the banner (not in segment/campaign already completed). If the status of banner components is also needed by the app, the following method can be used to check the banner content by registering a broadcast receiver:
1
BroadcastReceiver mMessageReceiver;
2
​
3
mMessageReceiver = new BroadcastReceiver() {
4
@Override
5
public void onReceive(Context context, Intent intent) {
6
// Extract data included in the Intent
7
try {
8
​
9
10
if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_BANNER_LOADED")) {
11
​
12
String data = intent.getStringExtra("data");
13
JSONObject jsonObject = new JSONObject(data);
14
15
System.out.println(jsonObject.toString());
16
// Output - {"banner1":2,"banner2":0}
17
// Key is the bannerId and value is number of banners in the Banner Component
18
// banner.setVisibility(GONE);
19
}
20
​
21
} catch (Exception e) {
22
System.out.println(e);
23
}
24
}
25
​
26
};
27
​
28
registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_BANNER_LOADED"));
Copied!

Setting up Floating Buttons and Popups

The given function should be used on every Activity's onResume Method to support adding the floating button/popup entry points on the activity via the dashboard:
1
@Override
2
protected void onResume() {
3
super.onResume();
4
CustomerGlu.getInstance().showEntryPoint(MainActivity.this);
5
}
Copied!

Handle CustomerGlu Notifications

To handle the notifications configured via CustomerGlu Dashboard (Push/In-app), use the given method:
1
customerGlu.displayCustomerGluNotification(this,json,R.drawable.icon,0.5);
Copied!
Add it in the Firebase onMessageRecieved callback, as shown below:
1
@RequiresApi(api = Build.VERSION_CODES.M)
2
@Override
3
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
4
super.onMessageReceived(remoteMessage);
5
JSONObject data = null;
6
JSONObject json = new JSONObject(remoteMessage.getData());
7
​
8
customerGlu.displayCustomerGluNotification(this,json,R.drawable.icon,0.5);
9
​
10
}
Copied!
Function Parameters:
  1. 1.
    context : this/getApplicationContext()
  2. 2.
    json : The json object of the remote message.
  3. 3.
    icon : The App Icon to be displayed for the push notifications.
  4. 4.
    opacity (optional) : The background opacity required for in-app notifications. Can take values between 0 to 1, where 0 means fully transparent and 1 means fully opaque background. (Default value is 0.5)
​
πŸ’‘
Note: App icon should be in PNG format with size less than 100KB.

Supported Layouts:

  1. 1.
    full-default
​
2. middle-default
​
3. bottom-default
​
4. bottom-slider (the screen can be minimized by dragging it down)
​
​

Send Events

This function can be used to directly send the events to the CustomerGlu :
​
πŸ’‘
Note: Check out all available options to send events here​
1
HashMap<String,Object> eventProperties = new HashMap();
2
eventProperties.put("orderValue",1000);
3
customerGlu.sendEventData(Context,"Order_Placed",eventProperties);
Copied!
Function Parameters:
  1. 1.
    Context : this/getApplicationContext()
  2. 2.
    EventName: Event names like order_placed, add_to_cart etc.
  3. 3.
    EventProperties - Event properties like orderId, orderAmountetc. as a HashMap
​

Handle Firebase Deeplinks for Referrals

If Firebase DynamicLinks are being used for referrals, the given function can be used to extract the referrer's userId. The referrer's userId can then be passed while registering the referred user (only valid for the first registration) as the referredBy property as seen here.
1
referID = customerGlu.getReferralId(deepLink);
Copied!
1
FirebaseDynamicLinks.getInstance()
2
.getDynamicLink(getIntent())
3
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
4
@Override
5
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
6
// Get deep link from result (may be null if no link is found)
7
Uri deepLink = null;
8
if (pendingDynamicLinkData != null) {
9
deepLink = pendingDynamicLinkData.getLink();
10
refer_id = customerGlu.getReferralId(deepLink); //extracting the referredBy Id
11
}
12
}
13
})
14
.addOnFailureListener(this, new OnFailureListener() {
15
@Override
16
public void onFailure(@NonNull Exception e) {
17
Log.e("k", "getDynamicLink:onFailure", e);
18
}
19
});
Copied!
​

Enable Pre-Caching

This will enable pre-caching to make the CustomerGlu UIs load faster by downloading the resources on local storage in advance (improved performance on slower networks):
1
customerGlu.enablePrecaching(context);
Copied!
​
⚠
Pre-caching requires an additional permission to be added to the AndroidManifest.xml file:
1
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
Copied!

Configure Loader Color

This function can be used to change the color of the loader which appears on the webview window while the webpage is being loaded.
​
πŸ’‘
Note: Default color is Black(# FF000000)
1
customerGlu.configureLoaderColour(context,color)
Copied!
Function Parameters:
  1. 1.
    Context : this/getApplicationContext()
  2. 2.
    Color : It accepts String value of hex color. (RGB: 6-digit hex, ARGB: 8-digit hex)

Disable CustomerGlu SDK

All the functions of SDK can be disabled by using the method:
1
customerGlu.disableGluSdk(true);
Copied!
​