Mobile SDKs
Integrating CustomerGlu on your Mobile Apps
Pre-Requisites
CustomerGlu Android SDK supports API 21 and above. Please ensure the minSDKVersion in the app's build.gradle file reflects the same.
Permissions
Add the following permissions to the AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />CustomerGlu iOS SDK supports IOS 12.0+ and requires Xcode 12 or above to build.
CustomerGlu Flutter SDK supports API 21 and above. Please ensure the minSDKVersion in the app's build.gradle file reflects the same.
Firstly add the permission of internet in Manifest file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />CustomerGlu iOS SDK supports IOS 11.0+ and requires Xcode 12 or above to build.
Installation
Add the following dependency to the app's build.gradle file:
dependencies{
implementation 'com.customerglu:CustomerGluLibrary:3.0.4'
}Add the below code snippet in project level build.gradle file:
allprojects {
repositories {
...
mavenCentral()
}
}For new Projects , add the below code snippet in settings.gradle file (if above not work):
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
mavenCentral()
}
}Option 1: Using CocoaPods
Add CustomerGlu to your Podfile and run pod install
pod 'CustomerGlu'
Option 2: Using Swift Package Manager
Add https://github.com/customerglu/CG-iOS-SDK as a Swift Package Repository in Xcode and follow the instructions to add Intercom as a Swift Package.

Option 1
Add the CustomerGlu Flutter plugin in pubspec.yaml file
Option 2
Run this command With Flutter:
Option 1
Add the CustomerGlu React Native plugin in package.json file
Option 2
Run this command With npm:
Initialise SDK
Add your WriteKey/API Key in meta-data of the AndroidManifest.xml file like this:
Define the global instance of CustomerGlu SDK in your Application class:
For Initialising SDK add the following line in your Application Class (Mandatory)
Add the following key to the Info.plist file.
Define the global instance of CustomerGlu SDK
You can store the global instance of CustomerGlu SDK in a variable so you don't have to use CustomerGlu.getInstance for each function call
For Initialising SDK add the following line in your AppDelegate (Mandatory)
To initialize the SDK, the initialization method must be called at every app launch before using any other method from the CG SDK. This should be done in main.dart at the entry point of the app. Use the following values to specify the region: "in" β Indian Region "me" β Middle-East Region "us" β USA Region
Add your WriteKey/API Key in meta-data of the AndroidManifest.xml file like this:
Add the following key to the Info.plist file:
Add your WriteKey/API Key in meta-data of the AndroidManifest.xml file like this:
To initialize the SDK the initialization method must be called at every app launch before using any other method from the CG SDK. use it in index.js at entry point of the app
Add the following key to the Info.plist file:
To initialize the SDK the initialization method must be called at every app launch before using any other method from the CG SDK. use it in index.js or App.js at entry point of the app
Register User (Mandatory)
Registering a user of your platform with CustomerGlu is mandatory to be able to show any CG powered UIs and experiences to the user. Users need not be registered on your platform. You can check out the flow to handle non-logged/guest users here.
As the same registration method can also be used to update user attributes, it is recommended to use this method on every app launch, after signing in/up and reaching the app home page.
This method is now used to register the user with CG. Make sure to call it on every App launch. In SDK v3.0.0 or above we are not accepting CustomAttributes here in the registerDevice:
Function Parameters:
Context: this/getApplicationContext()
userData: A HashMap that holds user information
Sample UserData object
Use the given function to register a user with CustomerGlu :
Sample UserData object
Use the given function to register a user with CustomerGlu :
Sample UserData object
UpdateUser Attributes
This method is used to update the user custom Attributes to add users to the respective segments
UpdateUser Profile
You can update the user profile and customAttributes values by using following method:
Clear Data on Logout (Mandatory)
Use the given function when the user logs out, to clear CustomerGlu SDK cached data like user_id, token, entry point related data, etc.
Handling Webview Events
CG Webviews send the following types of events to the app:
Deeplink redirection Events (OPEN_DEEPLINK): Redirect to a given screen on click of buttons from CustomerGlu UIs Example: Clicking on "Go To Cart" should redirect to the Cart Screen
Analytics Events (ANALYTICS): Send click analytics events on CG UI directly from the app to your servers/CDP Platform Example: coupon code copied event
Enable Analytics Events
If click analytics are to be captured directly via the app, you can enable the analytics events by using the given function:
Handling Events
Deeplink Events
For handling Deeplink events triggered by the webview, you need to add a notification observer:
Analytics Events
For handling analytics events triggered by the webview, you need to a notification observer:
For handling Deeplink and Analytics broadcast events in Flutter you need to create a MethodChannel and handle the logic for the respective event:
For handling Deeplink and Analytics broadcast events in React-Native you need to add following code in your js file :
Nudge Configuration
Nudge Configuration is an object that can be passed as an optional parameter to the openWallet, loadCampaignById and openNudge methods to configure the layout, height, and other related properties for the webview.
Relative Height - It accepts an integer value from 1 to 100 as Percentage(%) of device screen height. Default value: 70
Absolute Height - It accepts an integer value greater than 0. It follows native units like px (iOS) and dp (android) to adjust height. Default value: 0
3. Layout - Set the layout of nudge. Possible values: [full-default, middle-popup, bottom-popup, bottom-slider] | Refer here to see al supported layouts. Default value : full-default
4. closeOnDeepLink - If set to true , the Webview will be dismissed automatically if the user is redirected to an app screen from a button in the UI. Default value: false
5. Opacity - For any of the layouts except for fullscreen, set the background opacity of the screen not covered by content. It can take values between 0 to 1, where 0 means fully transparent and 1 means fully opaque background. Default value: 0.5
Open Wallet
CustomerGlu offers a fully customisable wallet page which contains challenges, games, rewards and other user specific information as shown below:

Use the following function to open the wallet screen powered by CustomerGlu:
Function Parameters
Context: this/getApplicationContext()
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Function Parameters
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Function Parameters:
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Function Parameters:
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Open Campaign
You can also open specific campaigns by using the campaignId or tag assigned to a campaign.
CampaignId

Tag

Use the following function to open a specific campaign:
Function Parameters
Context: this/getApplicationContext()
CampaignId/Tag : Unique Identifier assigned to a campaign, can be copied from the dashboard.
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Function Parameters
CampaignId/Tag : Unique Identifier assigned to a campaign, can be copied from the dashboard.
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Function Parameters
CampaignId/Tag : Unique Identifier assigned a campaign, can be copied from the dashboard.
NudgeConfiguration - Please refer to NudgeConfiguration
Function Parameters
CampaignId/Tag : Unique Identifier assigned a campaign, can be copied from the dashboard.
NudgeConfiguration(optional) : Please refer to the NudgeConfiguration
Verify CampaignId
You can verify the campaignId before opening the campaign using the below method
Above method returns the boolean value is the campaign valid or not.
Function Parameters
CampaignId/Tag : Unique Identifier assigned to a campaign, can be copied from the dashboard.
Entry Points
Entry Points are the various ways how users can discover and explore experiences like games, challenges, rewards, nudges, wallet, etc.
The following entry points are supported by CustomerGlu Mobile SDKs:
Banner
Floating Button/Launcher
Popup
Embed View
Banner Floating Button/Launcher

Popup

Enable Entry Points
Use the given function to enable Entry Points in the app (should be called on every app launch):
Setting up Banners
Banners need elements with unique ids to be pre-defined in the app screens. These components need to be added at all the places where banners need to show up- that is why it is important to add these elements generously, covering all possible use cases where a banner might be needed, as an app release will be required to edit them.
Add the following component, wherever a banner might be needed, in the Activityβs layout file (XML):
Banners can be set up in the following ways:
1. Storyboard / XIB
Drag and drop an empty UIView on the ViewController in which a banner might be needed, and adjust it to the correct position.
Under identity inspector add BannerView as the class name.
Under attribute inspector add a unique value for BannerId.
Height constraint can be added in the same view.
2. SwiftUI
If the app screens are developed using SwiftUI, add the following banner component, wherever a banner might be needed:
Add the following banner component, wherever a banner might be needed, in the flutter layout :
For Android:
In MainActivity add the following code in configureFlutterEngine to add BannerView:
Add the following banner component, wherever a banner might be needed, in the React-Native layout :
βΉοΈ Banner Loaded Callback:
The banner 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, for use cases like changing the parent container size, depending on visibility of the banner, the following method can be used to check the banner availability:
Register a Broadcast Receiver, listen for the banner load event and handle the logic:
Add a Notification Observer, listen for the banner load event and handle the logic:
Create a MethodChannel, listen for the banner load event and handle the logic:
Add the following code to listen for banner load event callback:
Setting up Embed View
Embed views can be used to embed CustomerGlu campaigns and screens directly in your native screens. Embed view works similar to Banners and needs elements with unique ids to be pre-defined in the app screens. These components need to be added at all the places where Embed view need to show up- that is why it is important to add these elements generously, covering all possible use cases where a Embed view might be needed, as an app release will be required to edit them.
Add the following component, wherever a banner might be needed, in the Activityβs layout file (XML):
Banners can be set up in the following ways:
1. Storyboard / XIB
Drag and drop an empty UIView on the ViewController in which a banner might be needed, and adjust it to the correct position.
Under identity inspector add CGEmbedView as the class name.
Under attribute inspector add a unique value for embedId.
Height constraint can be added in the same view.
2. SwiftUI
If the app screens are developed using SwiftUI, add the following banner component, wherever a banner might be needed:
Add the following embed component, wherever a embed view might be needed, in the flutter layout :
For Android:
In MainActivity add the following code in configureFlutterEngine to add BannerView:
Add the following embed component, wherever a embed view might be needed, in the React-Native layout :
Setting up Floating Buttons and Popups and PIP
As Floating Buttons and Popups are overlays, they need no special components to be predefined like Banners. They only need to be added on all screens/activities of the app and each screen should be assigned a name/identifier which can then be used to configure these entrypoints via the dashboard.
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:
The given function should be used on each ViewController's viewWillAppear() method to support adding the floating button/popup entry points via the dashboard:
The given code should be added on every Activity:
For Android:
The given function should be used in MainActivity , inside the onResume method to support adding the floating button/popup entry points on the activity via the dashboard:
The given function should be used on every Activity's useFocusEffect() Method to support adding the floating button/popup entry points on the activity via the dashboard:
Handle CustomerGlu Nudges
The push and in-app nudges sent via CustomerGlu need to be handled by the app.
Add the displayCustomerGluNotification method in the Firebase onMessageRecieved callback to handle nudges, as shown below:
Function Parameters:
context : this/getApplicationContext()
json : The json object of the remote message.
icon : The App Icon to be displayed for the push notifications.
opacity: For any of the layouts except for fullscreen, set the background opacity of the screen not covered by content. Can take values between 0 to 1, where 0 means fully transparent and 1 means fully opaque background. (Default value is 0.5)
autoclosewebview : If set to
true, the webview will be dismissed automatically if the user is redirected to an app screen from a button in the UI
Handling Nudges for Background/Killed State
Add the given snippet on the Splash Screen to fetch nudge data and then call the displayCustomerGluBackgroundNotification method on the same
Configure Notification Type
Set the sender of the nudge (Firebase/APNS) in the AppDelegate file:
Function Parameter
fcmApn: It accepts a string value out of "fcm" or "apn" depending on the notification service being used by the app.
Set FCM/APNS Token
Add following code in didFinishLaunchingWithOptions()
Add the following extension in AppDelegate:
Add your Notification icon in meta-data of the AndroidManifest.xml file like this:
Add the following method in the Firebase message listener:
Function Parameters:
autoclosewebview : If set to true , the webview will be dismissed automatically if the user is redirected to an app screen from a button in the UI.
Configure Notification Type
Set the sender of the nudge (Firebase/APNS) in the AppDelegate file:
Function Parameter
fcmApn: It accepts a string value out of "fcm" or "apn" depending on the notification service being used by the app.
Set FCM/APNS Token
Add following code in didFinishLaunchingWithOptions()
Add the following extension in AppDelegate:
Add the given dependencies in your application's
package.json file:
Import the given function:
Add it in the PushNotification library
onNotificationcallback, as shown below:
For Android -
Add your Notification icon in meta-data of the AndroidManifest.xml file like this:
For iOS
Create a file named
NotificationServices.jsin the src folder and add given code in the file:
Add the given code in
App.js:
Update the pod file as shown below and and install it again:
Configure Notification Type
Set the sender of the nudge (Firebase/APNS)
Function Parameter
fcmApn: It accepts a string value out of "fcm" or "apn" depending on the notification service being used by the app.
Set FCM/APNS Token
Add following code in
didFinishLaunchingWithOptions()
Add the following method in
AppDelegate.m:
Supported Layouts
The following layouts are supported by CustomerGlu Mobile SDKs for various functionalities like opening wallet, campaigns, nudges, etc.
Fullscreen Middle Popup

Bottom Popup Bottom Slider (Draggable)

Handling Dark Mode/Light Configuration
The dark mode settings in the CustomerGlu SDK (only v2.2.0+) can be configured using the following Methods
Handling Configuration Changes
For handling configuration changes like dark/light mode, orientation, etc., Flutter and React-Native apps need to implement this method in android MainActivity
Handling CustomerGlu Deeplinks
CustomerGlu provides Universal Deeplinks to access particular campaigns and wallet page. To support these deeplinks in the app and redirection to playstore/appstore in case the app is not installed, please follow the given steps:
Step 1
Put the intent-filter inside the activity tag in Android Manifest as below to handle navigation to that activity
Step 2
To get the intent data from url you need to add the following method in the OnCreate() of your activity
Function Parameter
activity : Pass the activity inside the method
Step 3
To handle deeplinks in a custom manner, add the listener in the Application Class to get the callback
Step 1
Add the Associate domain in your project

Step 2
For SwiftUI
Implement .onOpenURL for the Launch view defined in WindowGroup in Scene class
For UI Kit
Implement the following method in AppDelegate.swift file
Android Put the intent-filter inside the activity tag in Android Manifest
iOS Add the Associate domain in your project

Flutter
Add the callback in main.dart in method channel
Android Put the intent-filter inside the activity tag in Android Manifest
iOS Add the Associate domain in your project

React-Native
Implement the below callback:
Send Events (to CG)
User events which may lead to rewards via a campaign need to be sent to CG. These events can be sent directly via the SDKs using the sendEventData method:
Function Parameters
Context : this/getApplicationContext()
EventName: Event names like
order_placed,add_to_cartetc.EventProperties - Event properties like
orderId,orderAmountetc. as a HashMap
Function Parameters
eventName: Event names like
order_placed,add_to_cartetc.eventProperties - Event properties like
orderId,orderAmountetc as a dictonary.
Function Parameters
EventName: Event names like
order_placed,add_to_cartetc.EventProperties - Event properties like
orderId,orderAmountetc. as an object
Function Parameters:
EventName: Event names like
order_placed,add_to_cartetc.EventProperties - Event properties like
orderId,orderAmountetc. as an object
Enable SDK Debugging Mode
Debugging mode enables logging for ease of debugging.
The given function can be used to enable SDK debugging mode:
Disable CustomerGlu SDK
All the functions of SDK can be disabled by using the method:
Last updated
Was this helpful?