Android
Last update : 19/07/2022
Release version : 4.2.0
By using Data Commander product you will be able to store a lot of data and create segments of users. With those segments you can target precisely your offers to your customers or server personalized content in your application.
TCSegment is a small module especially made to get the segment of your user from within your application.
The Segment module is compiled with the following dependencies :
compile project(':core')
compile 'com.android.support:appcompat-v7:25.1.0'
For the creation of segments, please check the documentation of the Data Commander product.
The module needs some information to be able to fetch segments. It will need your siteID, the context of your application and also your security token. Your siteID and token are provided by TagCommander, the application context need to be provided by your application.
For debugging purpose, we recommand the use of TCDebug which will help you seeing what's happening inside the modules.
TCDebug.setDebugLevel(Log.VERBOSE);
TCDebug.setNotificationLog(true);
TCSegment.getInstance().setSiteIDAppContextAndToken(3311, this.getApplicationContext(), "e2032376eca5533858b7d6616d40802be54d221db1b75e1b");
We can't fetch Segments before the SDK fetched for the phone's Android Advertising ID, you might have to wait severals seconds after the initialisation of the Segment module.
Since fetching segments needs internet and is not instantaneous, getting the segments require two steps. First you will ask the module to fetch the segmentation, then you will be able to get the list of segment once the first operation ended by either registering to a notification or by asking directly the segment list.
To ask the module to fetch the segments, simply call the following line. Call it back each time you want to refresh the value.
TCSegment.getInstance().fetchSegments();
The simplest way to have the segment list as soon as possible is by listening to the notification sent by the module. Simply use your application context to get the LocalBroadcastManager and register your class as a listener of kTCNotification_SegmentAvailable.
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(main.getApplicationContext());
broadcastManager.registerReceiver(this, new IntentFilter(TCSConstants.kTCNotification_SegmentAvailable));
Then treat the notification in your onReceive method:
@Override public void onReceive(Context context, Intent intent) { String intentName = intent.getAction();if (intentName != null && intentName.equals(TCSConstants.kTCNotification_SegmentAvailable)) { // Do anything you want here }
}
If you don't want to or can't register to the notification, you can also simply call a method from the module that will give you the current list. Be carefull as it not synchroneous, the list may get updated after you asked for it.
List<String> segments = TCSegment.getInstance().getSegmentList();
If no segment are found or they were never fetched, the list will be empty and not null.
To check an example of how to use this module, please check:
Support support@commandersact.com
Commanders Act | 3/5 rue Saint Georges - 75009 PARIS - France
This documentation was generated on 19/07/2022 16:25:24
