Integration
Prerequisites and minimal setup
In this section, we explain how to get started with FollowAnalytics SDK for Android. Before you start, be sure to have all the necessary prerequisites. These include:
- Registering the application on the Platform
- Generating the API Key
Here are the minimal steps for integrating the SDK in your application:
- Installing the SDK in your app
- Initializing the SDK using your API key
- Registering for notifications
Once the integration is finished, you can validate your setup, and start tagging events and saving attributes in your application.
Install using Gradle
The best way to install the SDK is with Gradle:
-
Fetch the library from the private nexus repository
-
Add the FollowAnalytics repository to your
build.gradle
repositories.repositories { ... maven { url 'https://nexus.follow-apps.com/nexus/content/repositories/releases/' } }
-
Add the FollowAnalytics SDK to your module's
build.gradle
dependencies.dependencies { ... implementation "com.followapps.android:sdk:6.2.+" ... }
Once installation is over you will notice that dependencies and permissions are automatically added. For more information on dependencies and permissions, refer to the two subsections .
Dependencies
Using Gradle, dependencies will automatically be added while merging the manifest. The FollowAnalytics SDK depends on the following libraries:
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.google.android.gms:play-services-location:16.0.0"
implementation "com.google.firebase:firebase-messaging:17.4.0"
implementation "me.leolin:ShortcutBadger:1.1.19@aar"
ShortcutBadger dependency
The ShortcutBadger dependency allows devices to display the number of unread messages on the app icon. These are called badges and, unlike on iOS, they are automatically managed with this dependency.
Permissions
Automatically added permissions
Using Gradle, the SDK adds automatically the following permissions to your manifest.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Additional permissions
- To use the user location feature, add:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- To use the geofencing feature, add:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Android M and permissions
The following permissions are labelled as dangerous since Android 6.0 Marshmallow (find more information about dangerous permissions here):
- android.permission.ACCESS_COARSE_LOCATION
- android.permission.ACCESS_FINE_LOCATION (for geofencing feature).
Permissions and user experience
Note that each permissions results in a dialog being shown to your user. Instead of having them appear at installation, you can have them appear at the most relevant location in your app during runtime. To include permissions and keep a good user experience, we recommend you to follow the Android guidelines described here.
Initialize with your API key
Prepare your API key
Be sure to have your API key for this step of the configuration. If you are not sure where to find it, reach out to your Customer Success Manager or message support.
To initialize the FollowAnalytics SDK, call FollowAnalytics.init(Context context, Configuration configuration)
inside the onCreate()
method of the Application
class. This allows the SDK to be systematically initialized, whether the user launches the app himself, or if the Android system wakes a receiver or service of the app (for example, a push notification).
Open your Application subclass, or create a new one, and add the following lines to override the onCreate
method:
public class MyAwesomeApplication extends Application {
@Override
public void onCreate(){
[...]
FollowAnalytics.init(this.getApplicationContext(), new FollowAnalytics.Configuration() {
{
this.apiKey = "MY_API_KEY";
}
});
[...]
}
}
If you just created an Application subclass, remember to declare it in your AndroidManifest.xml
file:
<application
android:name=".MyAwesomeApplication"
/>
Register for notifications
Important
Push notifications on debug
mode don't work. If you wish to test your notifications, which is highly recommended, switch to release
mode.
Notification channel for Android 8.0 (Oreo)
Since Google has refactored its "Notification system" for Android 8.0 ("Oreo"), (details here) FollowAnalytics SDK uses default_notification_fa
as the id for the NotificationChannel
object.
The FollowAnalytics SDK supports push notifications based on Firebase Cloud Messaging. If you haven't done so already, you will need to add your project to Firebase in order to continue in the following steps. In this section we will explain to you how to use Firebase Cloud Messaging (or FCM) with the FollowAnalytics SDK. This means that we will cover:
Install Firebase Cloud Messaging
Get started with Firebase
Sending push notifications for Android requires Firebase Cloud Messaging, Google's standard messaging service. If you don't already use Firebase, you will need to do the following:
- Add Firebase to your project
- Create Firebase project to Firebase console
Before you start adding Firebase to your project, we recommend you take the time to familiarize yourself with firebase and its console. You will find this information (and much more) by referring to the Google documentation.
-
Add the library FCM to your
build.gradle
file in your application module.implementation "com.google.firebase:firebase-messaging:17.3.0"
-
Create a class that extends to
FirebaseMessagingService
and override the two methodsonMessageReceived
andonNewToken
.import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; public class MyFirebaseMessagingService extends FirebaseMessagingService { /** * Every push notification will arrive through this method */ @Override public void onMessageReceived(RemoteMessage remoteMessage) { } /** * Every new token will arrive through this method */ @Override public void onNewToken(String s){ } }
-
Add the following service tag in your
AndroidManifest
application file. Be sure that the value inandroid:name
is the relative path to your new service previously created.<service android:name=".MyFirebaseMessagingService"> <!-- Relative path of service class--> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service>
-
Finally, do not forget to copy the FCM Server key token (available through Firebase Console in your project settings).
and paste it to our platform in the application's administration.
Verify your Google Services configuration
Be sure to check the configuration of Google Services as they have to be the following if you want the FollowAnalytics SDK and Firebase to work.
- Version of Google Services that is at least 4.0.1
- The JSON for Google Services in your application is correct. It is accessible by doing select Project > App > google-services.json) is the same as the one in Firebase (which you can download from the Firebase Console
Interacting Firebase Cloud Messaging with FollowAnalytics SDK
Prerequisites for using Firebase
Before you begin, you need to have Firebase Cloud Messaging (FCM) installed in your project. Then only you can proceed to the integration.
If your app already uses Google Cloud Messaging (GCM) for your push notifications, you will need to migrate to Firebase Cloud Messaging (FCM) after installation. You can skip this section and follow the instructions here.
Now that you have installed FCM, you need it to interact with the FollowAnalytics SDK. For this, access the your Firebase Cloud Messaging Service class (a class we previously called MyFirebaseMessagingService
that was created and extended to FirebaseMessagingService
).
Set push token
FollowAnalytics.setPushToken(String token)
is a function that passes a FCM token to FollowAnalytics SDK. Add it to the functiononNewToken
.
For example:
@Override
public void onNewToken(String s){
android.util.Log.d(TAG, "Token is : "+s);
FollowAnalytics.setPushToken(s); // <-- Insert this method
}
Process Firebase Message
FollowAnalytics.processFirebaseMessage(Context context, RemoteMessage remoteMessage)
is a function that passes the push message notification to FollowAnalytics SDK.
This function must be added to onMessageReceived
in cases to transmit the push notification to FollowAnalytics SDK.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
FollowAnalytics.processFirebaseMessage(this, remoteMessage); // <-- Insert this method
}
Migrating from GCM to FCM
Prerequisites for using Firebase
Before you begin, you need to have Firebase Cloud Messaging (FCM) installed in your project. Then only you can proceed to the integration.
This section only applies to apps that already work with Google Cloud Messaging (GCM) and need to switch to Firebase Cloud Messaging. If you don't have GCM in you app, you need to do a standard integration, which is explained in the section above.
-
Remove any reference to GCM in your
build.gradle
file.dependencies { compile "com.google.android.gms:play-services-gcm:<VERSION>" }
-
Edit your app's manifest file by removing some required permissions and receiver functionality from GCM.
<uses-permission android:name="android.permission.WAKE_LOCK" /> <permission android:name="<PACKAGE_NAME>.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="<PACKAGE_NAME>.permission.C2D_MESSAGE" /> ... <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="<PACKAGE_NAME>" /> </intent-filter> </receiver> ... <service android:name=".MyInstanceIDListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.android.gms.iid.InstanceID" /> </intent-filter> </service> ... <service android:name=".MyGcmListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service>
-
Migrate the code available in
InstanceIDListenerService
class toFirebaseMessagingService
class.//BEFORE public class MyInstanceIDListenerService extends InstanceIDListenerService { ... @Override public void onTokenRefresh() { //Code available here } } //------------------------------------------------------------------------ //AFTER public class MyFirebaseMessagingService extends FirebaseMessagingService { ... @Override public void onNewToken(String s){ //Migrate the code here and do not forget to refactor your code FollowAnalytics.setPushToken(s); } }
Do not forget to refactor your code, due to Google API changes
-
Migrate the code available in
GcmListenerService
class toFirebaseMessagingService
class. Also do not forget to refactor your code, due to Google API changes.//BEFORE public class MyGcmListenerService extends GcmListenerService { ... @Override public void onMessageReceived(String from, Bundle data){ ..... //Code available here } } //------------------------------------------------------------------------ //AFTER public class MyFirebaseMessagingService extends FirebaseMessagingService { ... @Override public void onMessageReceived(RemoteMessage remoteMessage) { //Migrate the code here and do not forget to refactor your code FollowAnalytics.processFirebaseMessage(this, remoteMessage); } }
Do not forget to refactor your code, due to Google API changes
-
Finally, delete
InstanceIDListenerService
andGcmListenerService
class from your project.
Validate your setup
Validator
The SDK has a Validator that will ensure that everything is properly configured. To know more about what the validator can check and how, refer to its dedicated page.
Depending on how you wish to check your configuration with the Validator, use one of the two methods:
-
display the validator in a dialog:
if(Configuration.isApplicationInDebug()){ InstallationChecker.displaySDKConfigurationCheckingInDialog(ActivityContext); }
-
display the validator in the console:
if(Configuration.isApplicationInDebug()){ InstallationChecker.showSDKConfigurationInLog(this); }
Analytics
Events vs Attributes
The FollowAnalytics SDK allows you to tag both events and attributes. In this section, we explain how to utilize both of them in your app and benefit from analytics capabilities. If you are unsure about the difference, you may refer to the corresponding FAQ entry.
App logs
You can tag your app by adding logs to specific events and errors experienced by the user. These logs are then received and visible on the FollowAnalytics platform.
Logging best practices
To successfully empower your team with FollowAnalytics make sure your logs are relevant, read the Logging best practices entry in the FAQ section.
Regular, native logs
To add FollowAnalytics logs in your code, here are the two methods you can call from the SDK:
// Log an event without details
boolean FollowAnalytics.logEvent(String eventName);
boolean FollowAnalytics.logError(String errorName);
// Log an event with String details
boolean FollowAnalytics.logEvent(String eventName, String details);
boolean FollowAnalytics.logError(String errorName, String details);
// Log an event with Map details
// This is useful to pass pairs of key-values into a single event
boolean FollowAnalytics.logEvent(String eventName, Map<String, String> details);
boolean FollowAnalytics.logError(String errorName, Map<String, String> details);
Boolean return method value
All theses functions return a boolean value. If the value is true, it means that the log is valid and stored, otherwise false will be returned.
Use the name as the unique identifier of your log. Use the details to be more specific and add some context. The details field can either be a String or a Map, so that you can associate multiple key-values for additional context.
Events can be renamed on the FollowAnalytics platform
The name that you give to your event here can be overridden in the FollowAnalytics platform. For more information, reach out to your Customer Success Manager or message support.
For example, you can log the display of a view by writing the following:
FollowAnalytics.logEvent("Product Page", "Product #42");
FollowAnalytics.logError("Error log", "This is an error!");
Use a Map
for the details field, the value of which must contain a String type.
HashMap<String, String> detailsMap = new HashMap<String, String>();
detailsMap.put("product_id", "42");
detailsMap.put("product_category", "Jeans");
FollowAnalytics.logEvent("Add product to cart", detailsMap);
Parameters over 60Kb will be refused by the method. Running in debug mode, it will return returning NO
and write a message in the console.
Logging from a web view
This feature is limited to Android 4.2 and above
Logging from web view is a feature that is only activated for Android versions above 4.2 "Jelly Bean" (API Version >= 17) in order to prevent a security flaw in Google's Android SDK. You may find more details here in the documentation provided by Android.
If your app contains web views, you can also tag events and errors from within your HTML/JS code.
FollowAnalytics SDK Android has a class called FAWebView
which allows the integration in three steps.
-
Declare the
FAWebView
element into your<layout>.xml
. For instance:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="20dp" android:layout_width="match_parent" android:layout_height="match_parent" > <com.followapps.android.FAWebView android:layout_width="match_parent" android:id="@+id/fa_webview" android:layout_height="match_parent"/> </LinearLayout>
-
In the corresponding activity which uses the
<layout>.xml
layout, retrieve the ID associated withFAWebView
element integrated in the layout. For instance:FAWebView faWebView = (FAWebView) view.findViewById(R.id.fa_webview);
-
Inject the HTML file/page to the
FAWebView
element by using theloadUrl
method.faWebView.loadUrl("file:///android_asset/webView.html");
Notice that log events, user attributes and InApp properties can be used in the HTML file by using the following methods:
-
Log events/errors:
<a onclick="FollowAnalytics.logEvent('My event');"> Send event without detail </a> <a onclick="FollowAnalytics.logEvent('My event', 'My event details');"> Send event with detail </a> <a onclick="FollowAnalytics.logError('fromWebView without detail');"> Send error without detail </a> <a onclick="FollowAnalytics.logError('fromWebView with detail','Error detail');"> Send error with detail </a>
-
User Attributes:
<a onclick="FollowAnalytics.UserAttributes.setFirstName('Isaac');"> Set first name </a> <a onclick="FollowAnalytics.UserAttributes.setLastName('Newton');"> Set last name </a> <a onclick="FollowAnalytics.UserAttributes.setEmail('ali@followanalytics.com');"> Set email </a> <a onclick="FollowAnalytics.getDeviceId(displayDeviceID);"> Get Device ID </a>
-
InApp properties:
<a onclick="FollowAnalytics.InApp.pauseCampaignDisplay();"> Pause Campaign </a> <a onclick="FollowAnalytics.InApp.resumeCampaignDisplay();"> Resume Campaign </a>
Make sure to test if FollowAnalytics object exists with if (typeof FollowAnalytics !== 'undefined')
. This way, you can reuse the exact same HTML code for your mobile web site without impact.
User ID and attributes
This section covers the integration of a user ID and customer attributes. The SDK allows you to set values for attributes FollowAnalytics has predefined as well as custom attributes which you can make yourself.
You don't need a user ID to set attributes
Attributes are tied to the device when no user ID is provided. If a user ID is set, a profile is created server side and can be shared across apps.
In both cases, attributes can be used in segments and campaigns to target users.
User ID
What is a user ID?
If users can sign in somewhere in your app, you can specify their identifier to the SDK. Unique to each user, this identifier can be an e-mail address, internal client identifier, phone number, or anything else that ties your customers to you. This is what we call the user ID.
A user ID enables you to relate any event to a specific user across several devices. It is also an essential component for transactional campaigns. A common user ID enables you connect to a CRM or other external systems.
To register the user ID, use:
FollowAnalytics.setUserId(String UserId);
To remove the user identifier (for example in case of a sign out) use the following method:
FollowAnalytics.setUserId(null);
Predefined attributes
Predefined attributes are attributes that will be attached to default fields on your user profiles. FollowAnalytics SDK has the following properties for predefined attributes:
setFirstName(String firstName);
setLastName(String lastName);
setEmail(String email);
setBirthDate(Date birthDate);
setGender(Gender gender);
setCountry(String country);
setCity(String city);
setRegion(String region);
For example, to set user Joe's city to "Paris", you would proceed as follows:
FollowAnalytics.UserAttributes.setCity("Paris");
FollowAnalytics.UserAttributes.setFirstName("Joe");
Custom attributes
In addition to predefined attributes, you can add your own custom attributes to your code.
Always double check your custom attribute types
When a value for an unknown attribute is received by the server, the attribute is declared with the type of that first value.
If you change the type of an attribute in the SDK, values might be refused server-side. Ensure the attribute types match. This could be done by comparing with the ones you have in the profile data section of the product.
Set a custom attribute
To set your custom attributes, you can use methods that are adapted for each type: setInt
, setString
,setBoolean
, setDate
, setDateTime
and setDouble
.
For example, to set the user's job:
FollowAnalytics.UserAttributes.setString("occupation", "Taxi driver");
Delete a custom attribute value
You can delete the value of an attribute using its key. For example, to delete the user's job:
FollowAnalytics.UserAttributes.clear("occupation");
Set of attributes
You can add or remove an item to or from a set of attributes.
To add an item:
FollowAnalytics.UserAttributes.addToSet("fruits","apple");
FollowAnalytics.UserAttributes.addToSet("fruits","strawberry");
FollowAnalytics.UserAttributes.addToSet("fruits","lemon");
To remove an item:
FollowAnalytics.UserAttributes.removeFromSet("fruits","lemon"); // Removes "lemon" from set of fruits.
And to clear a set:
FollowAnalytics.UserAttributes.clearSet("fruits"); // Removes all the items from the set.
For further information, refer to the SDK header file.
Opt-Out Analytics
Deprecated methods since version 5.4.0
Be sure to update the next methods :
setCollectLogsAuthorization(boolean authorized)
, setCollectLocationLogsAuthorization(boolean authorized)
, canCollectLocationLogs()
, canCollectLogs()
with the appropriated methods available and explained below.
What is Opt-out analytics?
The SDK can be configured to no longer track user information. This is what we call to opt out of analytics.
Once opted-out, no new data is collected, nor is it stored in the application. New session are not generated at launch and nothing is sent back to the server. This data includes the following:
- tagged elements such as events, errors
- new user identification and attributes
- crash reports
When a user is opted-out of analytics, campaigns will continue to work with the following limitations:
- No Contextual campaigns - as they depend on log tracking
- No Transactional campaigns - as they depend on the user ID
- No Dynamic campaigns - as they depend on users entering a segment
- Campaigns filters will depend on old data (before the user opted-out)
All data collected before the user has opted-out is preserved within FollowAnalytics servers. This means that a user having opted-out will still receive campaigns based on data acquired before opting out (previous campaigns, existing segments, etc). The opt-in state is persisted between app starts (unless storage of the app is emptied).
Configuration
FollowAnalytics SDK is opt-in by default at the initialization. However you can set it to opt-out at initialization by setting the optInAnalyticsDefault
flag to false in the FollowAnalytics.Configuration
object passed to the initialization method.
This is only used to set the default opt-in value at initialization. Moreover you can change the opt-in value at runtime.
At runtime, FollowAnalytics SDK uses the value returned by FollowAnalytics.getOptInAnalytics()
to decide log collection. The default value of this property is explained in the previous subsection. Once changed, the new value is saved into persistent memory and remains the same at every launch of the application.
If you want to change the value of the opt-in state at runtime, use the setOptInAnalytics
method:
FollowAnalytics.setOptInAnalytics(boolean state); // <- state set to true is equal to opt-in, but state set to false is equal to opt-out
In order to retrieve the value of the opt-in state that FollowAnalytics SDK is handling at runtime, use the getOptInAnalytics
method:
FollowAnalytics.getOptInAnalytics();
GDPR
To request the data collected with FollowAnalytics SDK, use the following method :
FollowAnalytics.GDPR.requestToAccessMyData();
To delete the data that has been collected with FollowAnalytics SDK, use the following method :
FollowAnalytics.GDPR.requestToDeleteMyData();
Campaigns
Campaign basics
What we mean by campaigns are the messages that you send to your user from the FollowAnalytics platform. Currently, FollowAnalytics enables you to send two types of campaigns: push notifications and in-app campaigns. Push notifications allow you to send messages to your user's home screen, whereas an in-app is a messages that is displayed in the app while the user is actively using it.
In this section, we cover all you need for your app to receive the campaigns sent from the FollowAnalytics platform, and how you can add the features the fully take advantage of the SDK's capabilities.
Before you start, be sure that the SDK is properly initialized. This includes registration for push notifications, which is covered in the "Integration" section above.
Customize push notifications
Notification icon customization
The SDK will use your applauncher icon as default notification icon. You could change this by adding a ic_fa_notification.png
file in your drawable folders.
If you wish to have a custom background color on your notifications, you can add a value to your color.xml
: <color name="ic_fa_notification_color">#ff0000</color>
.
Be sure to follow Google's guidelines for notification icons on Android.
If you need to customize your push notifications, you have to extend this class FollowAnalytics.DefaultMessageHandler
and override the method onPushMessageNotificationBuilding(...)
to the class that you created.
For example:
public class FollowPushHandler extends FollowAnalytics.DefaultMessageHandler {
@Override
public void onPushMessageNotificationBuilding(Context context, NotificationCompat.Builder notificationBuilder, FollowAnalytics.Message message) {
//customize the notification
}
}
Then, add to the manifest file the path of the class that extends FollowAnalytics.DefaultMessageHandler
as a meta-data tag under the application tag. For example:
<meta-data android:name=“com.followanalytics.deeplinking.handler” android:value=“the_full_path_of_your_message_FollowPushHandler”/>
Now that everything is set up, customize your notification under the method onPushMessageNotificationBuilding
.
An example of adding buttons to the notification is available below.
@Override
public void onPushMessageNotificationBuilding(Context context, NotificationCompat.Builder notificationBuilder, FollowAnalytics.Message message) {
super.onPushMessageNotificationBuilding(context, notificationBuilder, message);
if (message.getCategory().equalsIgnoreCase("social")) {
PendingIntent pendingIntentActions1 = null; //your pendingIntent when user click on button like
PendingIntent pendingIntentActions2 = null; //your pendingIntent when user click on button comment
NotificationCompat.Action action1 = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send, "Like", pendingIntentActions1).build();
NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_help, "comment", pendingIntentActions2).build();
notificationBuilder.addAction(action1);
notificationBuilder.addAction(action2);
}
}
Deep-linking: URL, Parameters
Push notification campaigns created through FollowAnalytics allow to deep link to content in an app (not limited to your own). You can use either an App Link, or use a customized key-value parameters that are forwarded to your code.
App Links
SDK behavior
The SDK manages automatically App-Links. Be sure to follow the google documentation for internal deep-links of the application.
The SDK introduced the possibility to use direct App Links like twitter://messages
, which will send you to the corresponding screen inside of the Twitter application.
You're able to access the functionality by enabling the Deep Linking on the platform, when creating a campaign. There you'll find the field App Link that expects you to enter these type of URL schemas. It can either be an URL schema to an external app or for your own application.
Customizing deep-linking parameters
Customizing deep-linking parameters
Google provides it's own recommendations for implementing deep-linking which you can find here. If you wish to implement it differently, please read the content below.
In FollowAnalytics campaigns through the platform, you can specify deep-linking parameters, e.g. in your push messages or for in-app button actions.
These parameters are given to the developer's code by the SDK. It is then up to the developer to implement the deep-links in the app (specific path of screens, format of the arguments, etc.).
To obtain these parameters, extend the FollowAnalytics.DefaultMessageHandler
class, like in this example:
public class CustomMessageHandler extends FollowAnalytics.DefaultMessageHandler {
/**
* This method is executed with no App Links. Only key-values were set.
**/
@Override
public void onPushMessageClicked(Context context, Map<String, String> data) {
String value1 = data.get("a_custom_param_key");
if(value1 !=null && data.get(value1).equals("a_custom_param_value_expected")){
//Execute the code for the customized deep-link with a key : "a_custom_param_key" and a value : "a_custom_param_value_expected"
Intent intent = new Intent(context, SpecificActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}else{
//Let the SDK handle the notification
super.onPushMessageClicked(context, data);
}
}
/**
* This method is executed when an App Link was, at least, set (through the clients portal)
**/
@Override
public void onPushMessageClicked(Context context, String url, Map<String, String> data) {
//Do something with the url
}
@Override
public void onInAppMessageClicked(Context context, String buttonText, Map<String, String> data) {
// Same as the above method, but from a in-app message!
}
}
If you chose to define a custom MessageHandler
, you must declare it in your app manifest as meta-data:
<application>
[...]
<meta-data android:name="com.followanalytics.deeplinking.handler" android:value="fully_qualified_identifier_to_your_class"/>
[...]
</application>
Through the key value format, FollowAnalytics supports both standardized deep-linking (by defining the key you'll always use to give the path), and more direct parameter passing for simpler use cases integrations.
Regular deep-link is usually implemented using a Router, that will handle the URL called on the app and translate it into the display of the right page, with the right content.
Custom Handling of Rich Campaigns
What are Rich Campaigns?
Among the layouts available on the FollowAnalytics platform, you can choose "Custom web page" and "templates". These layouts are called Rich Campaigns. Our SDK provides a default display for Rich campaigns, but you can replace them with your one of your own.
Rich campaigns can be handled directly by the app code, instead of being shown automatically by the SDK. The behavior is defined when creating the campaign, using the "automatically display content" switch.
For campaigns where the content is not handled by FollowAnalytics, you will need to extend com.followapps.android.CustomRichCampaignBaseReceiver
and declare it in your AndroidManifest.xml
.
You'll need to use an intent-filter on BROADCAST_RICH_CAMPAIGNS_ACTION
. For example:
<receiver android:name=".RichCampaignDataReceiver" >
<intent-filter>
<action android:name="%YOUR_APP_PACKAGE_NAME%.BROADCAST_RICH_CAMPAIGNS_ACTION" />
</intent-filter>
</receiver>
Where %YOUR_APP_PACKAGE_NAME%
is your app package name.
The method onRichCampaignDataReceived
must be overridden. Rich campaign parameters are provided as method arguments:
- Campaign title:
title
- Campaign URL:
url
- Custom Parameters associated to the campaign:
customParams
Pausing and resuming in-app campaigns
What is pausing and resuming an in-app campaign?
Pausing campaigns are used to prevent in-app from being displayed on certain screens and views of your application. You may pause a screen of the app when it is too important, or is part of a process that is too important to be interrupted by an in-app (i.e a payment screen in the process of the user making a purchase).
When the screen is safe to display an in-app, you resume in-app campaigns. Any campaign that was supposed to be displayed when the mechanism wakes paused is stacked. It will be shown as soon as the mechanism is resumed. This way you can send send in-app campaigns without impacting the user experience.
To pause and resume campaigns, add the following methods in you code at the location you wish the pause and resume to take effect:
FollowAnalytics.InApp.pauseCampaignDisplay(); // will pause campaign display
FollowAnalytics.InApp.resumeCampaignDisplay(); // will resume campaign display
Create safe spaces for you in-app messages
Rather than pause everywhere you have an important screen or process, you can pause right at the initialization of the SDK and resume in the areas you think it is safe for in-app messages to be displayed.
Enable campaign archiving
FollowAnalytics SDK allows you to store all campaigns and push notifications received by your application. This makes them available for custom usage, like building an inbox. To enable this feature, add the following line in the app manifest under the tag application.
-
You can choose to enable the message archiving as following:
<meta-data android:name="com.followanalytics.message.push.enable" android:value="true" /> <meta-data android:name="com.followanalytics.message.inapp.enable" android:value="true" />
-
To get all in-app or push messages:
FollowAnalytics.InApp.getAll() //for in-app messages FollowAnalytics.Push.getAll() //for push notifications
-
To get an in-app or a push message by identifier:
FollowAnalytics.InApp.get(message.id) //for an in-app message FollowAnalytics.Push.get(message.id) //for a push notification
-
To delete an in-app or a push message:
FollowAnalytics.InApp.delete(message.id) //for an in-app message FollowAnalytics.Push.delete(message.id) //for a push notification
-
To mark as read an in-app or a push message:
FollowAnalytics.InApp.markAsRead(message.id) //for an in-app message FollowAnalytics.Push.markAsRead(message.id) //for a push notification
-
To mark as unread an in-app or a push message:
FollowAnalytics.InApp.markAsUnread(message.id) //for an in-app message FollowAnalytics.Push.markAsUnread(message.id) //for a push notification
Data Wallet
What is the Data Wallet?
The Data Wallet is a consent management and data declaration tool that helps you on your way to in compliance with GDPR.
Your Data Wallet puts together with what is called a policy. This policy which is created from the FollowAnalytics platform, is what brings together the legal texts, data categories, recipients and purposes you have determined in your Data Wallet. There could only be one policy at a time. Every time it is updated on the platform, the policy downloaded by the SDK.
All the data in the SDK will be in a JSON format and the developer will need to reorganize them in order to display them. The use of this feature is one of the most advanced for FollowAnalytics. We recommend that the developer working with the Data Wallet should be familiar with the FollowAnalytics and that most features were already installed.
The Data Wallet is one of the more advanced features provided by FollowAnalytics. In order to proceed you need to activate it in the Configuration object passed to the initialization.
Local Policy
FollowAnalytics SDK offers you the possibility to add a default policy file.
When no other policy is yet available, the SDK returns a default empty policy having version 0.0.
Follow these steps below in order to add the policy file in your project:
-
Create an
assets
folder in your app project. -
Add the policy file in the
assets
folder (policy file downloaded from the platform). -
Initialize
dataWalletDefaultPolicyPath
in the configuration, with the path of the policy file. The path must be a relative path from theassets
folder.
For instance :
[...]
FollowAnalytics.init(this.getApplicationContext(), new FollowAnalytics.Configuration() {
{
this.dataWalletDefaultPolicyPath = "FollowAnalytics/Policy.config"; // <- Path of the default policy file
}
});
[...]
Callback Policy
FollowAnalytics SDK has a callback method that is triggered whenever a significant policy version is retrieved (for instance, going from version 1.8 to 2.4). The method is triggered when the leftmost digit of the version is increased.
Read status
The read status of the policy is always set to false
whenever the callback method is triggered. A new major version of the policy has to be accepted again by the users of the app, even if they accepted a previous version.
Override onDataWalletPolicyChanged()
in Configuration to interact with the newest and significant updated policy in your application.
[...]
FollowAnalytics.init(this.getApplicationContext(), new FollowAnalytics.Configuration() {
@Override
public void onDataWalletPolicyChanged(){
//insert code to interact with your application
}
});
[...]
Policy methods
Get Policy
To access the latest available policy, call the method getPolicy
:
FollowAnalytics.DataWallet.getPolicy();
This method returns an object called Policy
. Policy
allows you to acquire and process the information related to the policy set in the Data Wallet (version, legal texts, data categories, etc).
Policy status
To check the read status of the policy, use the following method :
FollowAnalytics.DataWallet.isRead();
This method returns a boolean value.
To change the read status of the policy, use the method setIsRead(boolean read)
with a boolean value as parameter.
FollowAnalytics.Datawallet.setIsRead(boolean read);
The policy is read when the boolean parameter is true
and is not read when it is false
.
Watch face
Initialize FollowAnalytics SDK
Do not forget to initialize FollowAnalytics SDK by doing those steps:
Follow Analytics SDK can be used with a watch face.
The watch face architecture has a different approach relatively to Android architecture with their lifecycle that needs to be settle down.
Two different types of background and foreground states exist in CanvasWatchFaceService.Engine.class
:
- onVisibilityChanged()
- onAmbientModeChanged()
The method onVisibilityChanged()
will be executed whenever the watch face becomes visible or hidden in the smartwatch.
However, the method onAmbientModeChanged()
will be executed whenever the device enters or exits ambient mode (this mode will switch to a black (hidden seconds) and white display (displayed seconds)).
Now in order to use watch face with FollowAnalytics SDK, two methods are available :
FollowAnalytics.WatchFace.enterForeground();
FollowAnalytics.WatchFace.enterBackground();
The function FollowAnalytics.WatchFace.enterForeground()
triggers the information of entering in foreground.
The function FollowAnalytics.WatchFace.enterBackground()
triggers the information of entering in background.
Those methods must be added in two different places :
@Override
public void onAmbientModeChanged(boolean inAmbientMode) {
super.onAmbientModeChanged(inAmbientMode);
...
if (inAmbientMode) {
FollowAnalytics.WatchFace.enterBackground();
} else {
FollowAnalytics.WatchFace.enterForeground();
}
...
}
@Override
public void onVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
if (visible) {
...
FollowAnalytics.WatchFace.enterForeground();
} else {
FollowAnalytics.WatchFace.enterBackground();
...
}
...
}
Configuration
In order to customize the behavior of FollowAnalytics SDK, it is possible to change the default configuration by creating your own configuration in the project.
It can be achieved by creating an anonymous FollowAnalytics.Configuration
, see all parameters here.
public class MyAwesomeApplication extends Application {
public static boolean isPolicyCalled = false;
@Override
public void onCreate(){
[...]
FollowAnalytics.init(this.getApplicationContext(), new FollowAnalytics.Configuration() {
{
this.apiKey = "API_KEY";
this.archiveInAppMessages = true;
}
@Override
public void onDataWalletPolicyChanged() {
isPolicyCalled = true;
}
});
[...]
}
}
Or it can be achieved by creating a class that extends FollowAnalytics.Configuration
, see all parameters here.
import com.followanalytics.FollowAnalytics;
public class MyConfiguration extends FollowAnalytics.Configuration {
public static boolean isPolicyCalled = false;
public MyConfiguration(){
this.apiKey = "API_KEY";
this.archiveInAppMessages = true;
}
@Override
public void onDataWalletPolicyChanged(){
isPolicyCalled = true;
}
}
And then, you can initialize FollowAnalytics SDK with instantiating and passing the configuration object. For Instance:
public class MyAwesomeApplication extends Application {
@Override
public void onCreate(){
[...]
FollowAnalytics.init(this.getApplicationContext(), new MyConfiguration());
[...]
}
}
Parameters
A description table with the properties that can be modified with FollowAnalytics.Configuration
.
Parameter | Type | Default Value | Description |
---|---|---|---|
apiKey |
String | "" | Your app api key to use our SDK |
isVerbose |
boolean | false | To see internal logs made by the SDK through Logcat |
apiMode |
enum | ApiMode.PROD | To avoid sending irrelevant logs to the production server |
environment |
String | "" | If you want to use a custom environment |
environmentDomain |
String | "follow-apps.com" | If you want to use a custom domain |
environmentProtocol |
String | "https" | By default we use https, you can change it to http |
optInAnalyticsDefault |
boolean | true | To choose your default opt-in / opt-out behavior |
isDataWalletEnabled |
boolean | false | To enable or disable the DataWallet |
dataWalletDefaultPolicyPath |
String | null | To determine the path of your local dataWallet policy |
onDataWalletPolicyChange |
call back | -- | Called when a new significant version of dataWallet policy is available |
archivePushMessages |
boolean | false | To choose if you want to archive push messages or not |
archiveInAppMessages |
boolean | false | To choose if you want to archive inApp messages or not |
maxBackgroundTimeWithinSession |
int | 120 | To determine the lifetime of a session when in background (between 15 and 3600) |
onConsoleLog |
call back | -- | Called when new logs are made internally in FollowAnalytics SDK |
Advanced Use Cases
Proguard
If you need to obfuscate and/or shrink your app before Google Play publication, be sure you protect the FollowAnalytics SDK, otherwise logs won't be sent.
Here is the ProGuard configuration:
-keep class com.followanalytics.** { *; }
-keep interface com.followapps.android.** { *; }