Xamarin FollowAnalytics SDK versions
The current versions of the FollowAnalytics SDK for Xamarin are based on the native SDK. The versions of these native SDKs are the following:
Integration
The FollowAnalytics SDK Xamarin component provides full bindings to the FollowAnalytics SDK for use in Visual Studio. With this component, Xamarin developers can target both iOS and Android devices with access to the full scope of the FollowAnalytics SDK, all while remaining in the C#/.NET ecosystem.
This document will cover app setup and the component installation process, as well as basic integration steps for iOS and Android.
For more information, please read the iOS and Android FollowAnalytics SDK documentations.
Prerequisites and minimal setup
In this section, we explain how to get started with FollowAnalytics SDK for Xamarin. 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 app:
- Installing the SDK in your app
- Initializing the SDK using your API key
- Registering for notifications and location
Once the integration is finished, we highly recommend you test the setup. You will find out how to test your setup in this section. Then, you can start tagging events and saving attributes in your app.
Installation
Download the FollowAnalytics SDK from the developer portal.
iOS
To install the iOS part of the SDK, follow these steps:
- Right Click on project References.
- Choose the
.Net Assembly
tab. - Go to
Browse...
- Add
FollowAnalyticsSDK.iOS.dll
to your iOS Xamarin project References.
Dynamic registrar issue
If there is any dynamic registrar issue
, you need to add --optimize=-remove-dynamic-registrar
flag to MTouchExtraArgs in iOS Build
tab in the project settings.
Android
To install the Android part of the SDK, add FollowAnalyticsSDK.Android.dll
to your References folder available in Android Xamarin project.
Initialize with your API keys
Be sure to have your API key
Be sure to have your API key for this step of the configuration. You can retrieve you app's API key from the administration section of the FollowAnalytics platform (see here)
iOS
- In your
AppDelegate.cs
add at the top:
using FollowAnalyticsSDK;
- In the method
FinishedLaunching
, right after theloadApplication
, add:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
...
FollowAnalytics.Configuration configuration = new FollowAnalytics.Configuration((obj) =>
{
obj.apiKey = "YOUR_API_KEY";
obj.isVerbose = true; //Optional, false by default
obj.archiveInAppMessages = false; //Optional, true if you want to archive your inApp message in the app
obj.archivePushMessages = false; //Optional, true if you want to archive your push message in the app
obj.isDataWalletEnabled = false; //Optional, true if you want to receive new data wallet if exist
obj.crashReportingEnabled = true; //Optional, false if you don't want to receive crash report
obj.maxBackgroundTimeWithinSession = 120; //Optional, you can change it for a value in [15,3600]
obj.optInAnalyticsDefault = true; //Optional, false if you don't want to receive logs
obj.onDataWalletPolicyChange = { }; //Optional
obj.onIncomingDeepLink = delegate(IDictionary<string,string> parameters, string actionIdentifier, string actionTitle) => // Optional
{
// YOUR_IMPLEMENTATION
};
obj.onConsoleLog = delegate(string message, FollowAnalytics.Severity severity, string[] tags) // Optional
{
// YOUR_IMPLEMENTATION
};
obj.onNotificationTapped = delegate(Uri url, IDictionary<string,string> parameters) // Optional
{
// YOUR_IMPLEMENTATION
// To open received URL you can use this code :
if (url != null)
{
UIApplication.SharedApplication.OpenUrl(url);
}
};
obj.onNotificationReceived = delegate(FollowAnalytics.Message message) // Optional
{
// YOUR_IMPLEMENTATION
// The message is an object that contain :
// bool isRead;
// bool isPush;
// bool isSilent;
// bool isInApp;
// string identifier;
// DateTime dateReceived;
// string campaignId;
// string messageType;
// string title;
// string body;
// string url;
// string layout;
// string deepLinkUrl;
// IDictionary parameters;
// IDictionary rawData;
// you need to check nullability of attributes
// To open received URL you can use this code :
if (message.DeepLinkUrl != null)
{
UIApplication.SharedApplication.OpenUrl(message.DeepLinkUrl);
}
};
});
FollowAnalytics.iOS.Init(configuration, launchOptions);
...
}
Android
Google Play Service version
The SDK requires version 8.4.0 or higher of the google-play-service
dependency. Install or update it from the Android Extras section using the Android SDK manager (run android
).
To initialize FollowAnalytics SDK, you need to configure FollowAnalytics SDK by creating the Configuration and setting the api key.
Create a class that extends Application
and call FollowAnalytics.Android.Init(Context context, FollowAnalytics.Configuration configuratio)
in the onCreate()
method of your class.
This is necessary to have the SDK initialized in all cases: either when app is launched by the user, or when the Android OS wakes the app (for example, at push notification receiving).
Open your Application subclass, or create a new one, and add the following lines to override the onCreate
method:
using System;
using Android.App;
using Android.Util;
using Android.Runtime;
using FollowAnalyticsSDK;
namespace FollowAnalyticsSDK.Android.Sample {
[Application(Label = "@string/app_name")]
public class MyApplication : Application {
public MyApplication(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip) {
}
public override void OnCreate() {
base.OnCreate();
FollowAnalytics.Configuration mConfig = new MyConfiguration(); // Configuration class created
FollowAnalytics.Android.Init(this, mConfig);
}
}
}
If you just created an Application subclass, remember to declare it in your AndroidManifest.xml
file:
<application
android:name=".MyApplication"
/>
Custom Configuration
In order to customize the behavior of FollowAnalytics SDK, it is possible to change the default configuration.
You can customize Opt-Out analytics and Datawallet.
In order to achieve this, you need to :
- create a class that extends to
FollowAnalytics.Configuration
with the attributes that are necessary to be changed and override call backs :
using FollowAnalyticsSDK;
namespace FollowAnalyticsSDK.Android.Sample
{
public class MyConfiguration : FollowAnalytics.Configuration
{
public MyConfiguration() {
this.ApiKey = "YOUR_API_KEY";
this.IsDataWalletEnabled = false; //Optional, true if you want to receive new data wallet if exist
this.OptInAnalyticsDefault = true; //Optional, false if you don't want to receive logs
this.ArchiveInAppMessages = false //Optional, true if you want to archive your inApp message in the app
this.ArchivePushMessages = false; //Optional, true if you want to archive your push message in the app
this.IsVerbose = false; //Optional, true if you want all the debug logs
this.MaxBackgroundTimeWithinSession = 120; //Optional, you can change it for a value in [15,3600]
this.DataWalletDefaultPolicyPath = ""; //Optional, to determine the path of your local dataWallet policy
}
public override void OnDataWalletPolicyChanged() // Optional, called when a new significant version of dataWallet policy is available
{
// YOUR_IMPLEMENTATION
}
public override void OnConsoleLog(string p0, Com.Followanalytics.FollowAnalytics.Severity p1, string[] p2) // Optional, called when new logs are made internally in FollowAnalytics SDK
{
// YOUR_IMPLEMENTATION
}
public override void OnNotificationReceived(Com.Followanalytics.FollowAnalytics.IMessage p0) // Optional, called when new app received a notification
{
// YOUR_IMPLEMENTATION
// The message is an object that contain :
// string Body
// string Id
// string CampaignId
// string ReceivedDate
// string IsRead
// string MessageType
// string Title
// string DeepLinkUrl
// bool IsPush
// bool IsSilentPush
// Map<String, String> Params
}
}
}
Now, FollowAnalytics SDK will start by default with the value associated in the customized configuration class.
Necessary project capabilities
iOS
Add a push certificate for notifications
FollowAnalytics requires a valid p12
or p8
certificate in order to communicate with Apple Push Notification Services (APNS). This certificate is generated for a unique Application Identifier (App ID).
Certificates have an expiration date
Your certificates are only valid for a year. Remember to update them, otherwise you will not be able to send push notifications any more.
We recommend to use p8 file
we strongly recommend using p8 file because you need to generate only one p8 to all your apps.
Generate and import a .p12
push certificate
To generate your push certificate:
-
Connect to your developer portal, and go to the App IDs.
-
Click on your Application Identifier to edit your app configuration if it exist or Create a new App ID by clicking in the
+
button in the top of page. -
In the list of Capabilities, check the Push Notifications box
-
Click Edit to display the window for Apple Push Notification service SSL Certificates
-
Create a certificate by clicking the Create button
-
Upload your Certificate Signing Request (create a Certificate Signing Request here) and click continue
-
Click Download button to create your certificate, open the Keychain Assistant app and locate that certificate
-
From the Keychain Assistant app, click the certificate line and export the
.p12
file by right-clicking on the profile below the certificate. Enter a password for your certificate. -
Go to the Administration page, upload the
.p12
file and enter the password you've entered on the previous step.
Do not forget to ensure your provisioning profile has the Push Notifications service enabled by expanding it from the list in your developer portal.
Generate and import a .p8
server Key
To generate your server key (p8)
-
Connect to your developer portal.
-
Click on your
Keys
tab. -
Click in the
+
button in the top of page to add a new Key. -
Add a
Key Name
. -
Check the
Apple Push Notification service (APNs)
-
Click
Continue
. -
Download the
.p8
file. (You must download the p8 file in this step because this is your unique chance to download it) -
Go to the
Identifiers
Tab. -
Click on your Application Identifier to edit your app configuration if it exist or Create a new App ID by clicking in the
+
button in the top of page. -
In the list of Capabilities, check the Push Notifications box
-
Go to the Administration page, upload the
.p8
file and click inProceed
. -
Enter your
Key ID
andIssuer Key
. You can find you Key ID in the Keys tab in the developer account and the Issuer Key is you team ID and you can find it by clicking in the View Membership in the developer account also.
Do not forget to ensure your provisioning profile has the Push Notifications service enabled by expanding it from the list in your developer portal.
After that, you need to go to your project in Visual Studio :
-
Open your info.plist file
-
Enable Background Modes
-
Check Remote Notification and Background fetch
-
Open your Entitlements.plist
-
Scroll down
-
Check the push notification capabily
Finnaly, you need to add a call to registerForPush
following the initialization line you added previously:
FollowAnalytics.RequestNotificationCenterDefaultAuthorisation();
Android
Build in release mode
The application must be built in release mode in order to receive push notifications
Notification channel for Android 8.0 (Oreo)
Since Google has refactored of its "Notification system" for Android 8.0 ("Oreo"), (details here) FollowAnalytics SDK uses default_notification_fa
as an id for 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 create/add a Firebase Project in Firebase Console in order to continue the following steps.
-
Add the required Packages to your project
Xamarin.Firebase.Common Xamarin.Firebase.Iid Xamarin.Firebase.Messaging
-
Add those FCM Receiver tags to your manifest
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
-
Create a class that extends to
FirebaseInstanceIdService
and override the methodOnTokenRefresh
:using Android.App; using Firebase.Iid; using Android.Util; using FollowAnalyticsSDK; namespace FollowAnalyticsSDK.Android.Sample { [Service] [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })] public class MyFirebaseIIDService : FirebaseInstanceIdService { const string TAG = "MyFirebaseIIDService"; public override void OnTokenRefresh() { var refreshedToken = FirebaseInstanceId.Instance.Token; Log.Debug(TAG, "Refreshed token: " + refreshedToken); FollowAnalytics.Android.SetPushToken(refreshedToken); ... } } }
-
Add the
FirebaseInstanceIdService
service tag in yourAndroidManifest
application file by changing the value associated withandroid:name
. In order to do this, you need to retrieve the value associated to the name of the Android Callable Wrapper for your custom implementation. The easiest way to get the value at runtime, is to implement the following code://import the namespace in your activity using Android.Util; //implement this code in one of the lifecycle method of your activity Log.Debug("FA","The MyFirebaseIIDService name is : " + Java.Lang.Class.FromType(typeof(<ABSOLUTE_PATH_OF_THE_CLASS>.<NAME_OF_THE_FIREBASE_INSTANCE_ID_SERVICE>)).Name);
For instance:
Log.Debug("FA", "The MyFirebaseIIDService name is : " + Java.Lang.Class.FromType(typeof(MyFirebaseIIDService)).Name);
This will output a similar result, at runtime, in the Logcat console:
FA D The MyFirebaseIIDService name is : md56f33aca13e7603ac857c2a0fb45b66ab.MyFirebaseIIDService
Finally, copy the result and paste it to
android:name
value as shown below:<service android:name="md56f33aca13e7603ac857c2a0fb45b66ab.MyFirebaseIIDService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service>
-
Do not forget to add those next lines of code inside of
OnTokenRefresh
method :var refreshedToken = FirebaseInstanceId.Instance.Token; // Function that retrieves a FCM token FollowAnalytics.Android.SetPushToken(refreshedToken); // Function that pass the FCM token retrieved to FollowAnalytics SDK
-
Create a class that extends to
FirebaseMessagingService
and override the methodOnMessageReceived
:using Android.App; using Android.Content; using Firebase.Messaging; using FollowAnalyticsSDK; namespace FollowAnalyticsSDK.Android.Sample { [Service] [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] public class MyFirebaseMessagingService : FirebaseMessagingService { public override void OnMessageReceived(RemoteMessage message) { FollowAnalytics.Android.ProcessFirebaseMessage(Application.Context, message); } } }
-
Add the
FirebaseMessagingService
service tag in yourAndroidManifest
application file by changing the value associated withandroid:name
. In order to do this, you need to retrieve the value associated to the name of the Android Callable Wrapper for your custom implementation. The easiest way to get the value at runtime, is to implement the following code://import the namespace in your activity using Android.Util; //implement this code in one of the lifecycle method of your activity Log.Debug("FA","The MyFirebaseMessagingService name is : " + Java.Lang.Class.FromType(typeof(<ABSOLUTE_PATH_OF_THE_CLASS>.<NAME_OF_THE_FIREBASE_MESSAGING_SERVICE>)).Name);
For instance:
Log.Debug("FA", "The MyFirebaseMessagingService name is : " + Java.Lang.Class.FromType(typeof(MyFirebaseMessagingService)).Name);
This will output a similar result, at runtime, in the Logcat console:
FA D The MyFirebaseMessagingService name is : md56f33aca13e7603ac857c2a0fb45b66ab.MyFirebaseMessagingService
Finally, copy the result and paste it to
android:name
value as shown below:<service android:name="md56f33aca13e7603ac857c2a0fb45b66ab.MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
-
Do not forget to add the next lines of code inside of
OnMessageReceived
method :FollowAnalytics.Android.ProcessFirebaseMessage(Application.Context, message); // Pass the push notification to FollowAnalytics SDK
-
Download the
google-services.json
file in your Firebase Project and add it to your Xamarin Project. -
Set the
GoogleServicesJson
as action to yourgoogle-services.json
by right clicking the file. -
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.
- The JSON for Google Services in your application is correct. Compare if it is the same as the one in Firebase (which you can download from the Firebase Console)
Define the URL scheme
To allow users to retrieve their device ID for campaign testing and tagging plan debugging, you need to define a URL scheme in your iOS and Android projects.
iOS
-
Make sure that the Rivets component is installed. If not, install with NuGet.
-
Open your app's Info.plist file, and under the Advanced tab, in the URL Types section, add a new URL Type like:
-
Make sure that the bundle ID of your app appears in the URL Schemes field as shown in the screenshot (where
com.follow-apps.followme.inHouse
needs to be replaced).
Android
- Edit your AndroidManifest.xml file to add this:
<activity android:name="com.followapps.android.internal.activities.DeviceIdActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="followanalytics.com"
android:path="/deviceId"
android:scheme="%YOUR_APP_PACKAGE_NAME%" />
</intent-filter>
</activity>
- Replace
%YOUR_APP_PACKAGE_NAME%
with the Android package name of your app.
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.
Data sent in debug mode will not appear on dashboards
When your application runs in DEBUG
mode or in a simulator, the data is automatically sent as development logs, and is therefore not processed to be shown on the main UI page. DEBUG
logs can be checked using the method given in the FAQ section.
See related entry in FAQ for more information on debug & release modes.
App tags
The SDK allows you to implement log events and errors in your code. The following methods that you can call with the SDK are the following:
FollowAnalytics.LogEvent(string eventName);
FollowAnalytics.LogEvent(string eventName, string details);
FollowAnalytics.LogEvent(string eventName, IDictionary<string, string> details);
FollowAnalytics.LogError(string eventName);
FollowAnalytics.LogError(string eventName, string details);
FollowAnalytics.LogError(string eventName, IDictionary<string, string> details);
Logging best practices
To ensure your tags are relevant and will end up empowering your team through FollowAnalytics, please read the Logging best practices entry in the FAQ section.
Use the eventName as the unique identifier of your tag. Use the details section to add specific details or context. Events can be renamed later: the name that you give to your event here can be overridden in the FollowAnalytics UI.
The details field can either be a String or a Hash, so that you can associated multiple key-values for additional context.
For instance, logging the appearance of a view could be done the following way:
FollowAnalytics.LogEvent("Product view", "Product reference");
var options = new Dictionary<string, string>();
options["product_id"] = "ABCD123";
options["product_category"] = "Jeans";
FollowAnalytics.LogEvent("Add product to cart", options);
User ID and attributes
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 and can be shared across applications.
In both cases, attributes can be used in segments and campaigns to target users.
User ID
If users can sign in somewhere in your application, you can specify their identifier to the SDK. This way, you will be able to relate crashes to specific users, link your users between FollowAnalytics and your CRM, and more.
It is recommended to use a cryptographic number that uniquely ties your customer to you.
To register the user identifier, use:
FollowAnalytics.SetUserId("1547521wed2155w57e02dwe574");
If you want to remove the user identifier (in case of a sign out for instance) use the following method:
FollowAnalytics.SetUserId(null);
At any moment, you can retrieve the current user ID this way:
string user_id = FollowAnalytics.GetUserId(); // returns null if there is no user id
Predefined attributes
The SDK allows to set values for both custom and predefined attributes.
For predefined attributes, the SDK has the following properties:
FollowAnalytics.UserAttributes.SetFirstName("Peter");
FollowAnalytics.UserAttributes.SetLastName("Jackson");
FollowAnalytics.UserAttributes.SetCity("San Francisco");
FollowAnalytics.UserAttributes.SetRegion("California");
FollowAnalytics.UserAttributes.SetCountry("USA");
FollowAnalytics.UserAttributes.SetGender(FollowAnalytics.Gender.Male);
FollowAnalytics.UserAttributes.SetEmail("mail@mail.com");
FollowAnalytics.UserAttributes.SetDateOfBirth(DateTime.Today);
FollowAnalytics.UserAttributes.SetProfilePictureUrl("https://picture/picture");
They are "predefined" in the sense that they will be attached to default fields on your user profiles.
To unset an attribute, set it to null
. For instance :
FollowAnalytics.UserAttributes.SetFirstName(null);
Custom attributes
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. Please ensure the types match by visiting 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:
FollowAnalytics.UserAttributes.SetNumber("key_number", 1);
FollowAnalytics.UserAttributes.SetNumber("key_double", 32.428);
FollowAnalytics.UserAttributes.SetDate("key_date", DateTime.Today);
FollowAnalytics.UserAttributes.SetDateTime("key_dateTime", Date.Now);
FollowAnalytics.UserAttributes.SetString("key_string", "string");
FollowAnalytics.UserAttributes.SetBoolean("key_bool", true);
For example, to set the user's job:
FollowAnalytics.UserAttributes.SetString("job", "Taxi driver");
Delete a custom attribute value
You can clear the value of an attribute using its key. For instance, to delete the user's job:
FollowAnalytics.UserAttributes.Clear("job");
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");
To add several items:
FollowAnalytics.UserAttributes.AddToSet("fruits", "orange", "banana");
To remove an item:
FollowAnalytics.UserAttributes.RemoveFromSet("fruits", "orange");
And to clear a set:
FollowAnalytics.UserAttributes.ClearSet("fruits");
Opt-Out Analytics
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 app. 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).
To inspect and set the opt-out state, call the following methods on FollowAnalytics class:
FollowAnalytics.SetOptInAnalytics(bool optInAnalytics);
FollowAnalytics.GetOptInAnalytics();
Please see additional doc in the new FollowAnalytics and FollowAnalyticsConfiguration interface for more details.
Additionally, if the opt-in by default policy doesn't suit your use case you can change it by setting the optInAnalyticsDefault
on FollowAnalyticsConfiguration.
bool optInAnalyticsDefault;
GDPR
You can record when the user expresses his demand to access or delete his personal data by calling one of the following methods:
FollowAnalytics.GDPR.RequestToAccessMyData();
FollowAnalytics.GDPR.RequestToAccessMyData();
The SDK will record all requests and send them to FollowAnalytics servers as soon as network conditions allow it. The SDK remembers pending requests between app restarts.
Campaigns
Deep-linking: URL, Parameters
Campaigns created through FollowAnalytics allow to deep link to content in your app. You can either use an App Link, or use key-value parameters that are forwarded to your code.
App Links
Version 4.1.0 of the SDK introduced the possibility to use direct App Links like twitter://messages
, which will send you to the corresponding screen inside the Twitter application.
You're able to access the functionality by enabling the Deep Linking switch in our UI, when creating a campaign. There you'll find the field App Link that expects you to enter these types of URL schemas. It can either be an URL schema to an external application or for your own application.
Deep-linking parameters
In FollowAnalytics campaigns, 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-linking in the app (specific path of screens, format of the arguments, etc.).
iOS
To handle url opening in your app, you have to implement your expected behavior in the OpenUrl
iOS callback of your AppDelegate :
public bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
// YOUR_IMPLEMENTATION (redirection to specific view)
return true;
}
Up to 6.1.2 Xamarin SDK version, you used OnIncomingDeepLink (parameters, actionIdentifier, actionTitle)
for deepLink parameters wich is deprecated since 6.2.0.
Since 6.2.0, there are tow new callbacks to handle Url and Parameters :
onNotificationTapped
To handle url or custom parameters received after a notification is tapped, your Configuration object must contain the obj.onNotificationTapped
callback with your expected behavior:
FollowAnalytics.Configuration configuration = new FollowAnalytics.Configuration((obj) =>
{
...
obj.onNotificationTapped = delegate(Uri url, IDictionary<string,string> parameters)
{
// YOUR_IMPLEMENTATION
// To open received URL you can use this code :
if (url != null)
{
UIApplication.SharedApplication.OpenUrl(url);
}
}
});
The onNotificationTapped
callback handles the tap on:
- Scheduled Push notifications
- Contextual Push notifications
onNotificationReceived
In order to receive the custom parameters sent within a Push Notification or an In App message payload, your Configuration object must contain the obj.onNotificationReceived
callback with your expected behavior:
FollowAnalytics.Configuration configuration = new FollowAnalytics.Configuration((obj) =>
{
...
obj.onNotificationReceived = delegate(FollowAnalytics.Message message)
{
// YOUR_IMPLEMENTATION
// Message argument fields you can access :
// bool isRead;
// bool isPush;
// bool isSilent;
// bool isInApp;
// string identifier;
// DateTime dateReceived;
// string campaignId;
// string messageType;
// string title;
// string body;
// string url;
// string layout;
// string deepLinkUrl;
// IDictionary parameters;
// IDictionary rawData;
}
});
The onNotificationReceived
callback handles the reception of:
- Scheduled Push notifications when app is in foreground
- Contextual Push notifications when app is in foreground
- Silent Push notifications when app is in foreground or background
Breaking change from 5.x
If you used SDK5.0, the method FollowAppsShouldHandleParameters
has been replaced with onNotificationTapped
and onNotificationReceived
callbacks.
Android
In FollowAnalytics campaigns through our 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-linking in the app (specific path of screens, format of the arguments, etc.).
To obtain these parameters, you can extend the FollowAnalytics.DefaultMessageHandler
class, like in the following example:
//import the namespace
using System.Collections.Generic;
using Android.Content;
....
public class CustomMessageHandler : FollowAnalytics.DefaultMessageHandler
{
public override void OnInAppMessageClicked(Context context, string buttonText, IDictionary<string, string> p2){
base.OnInAppMessageClicked(p0,p1,p2);
//Write code to process information
}
public override void OnPushMessageClicked(Context context, string url, IDictionary<string, string> parameters){
base.OnPushMessageClicked(context, url, parameters);
//Write code to process information
}
public override void OnPushMessageClicked(Context context, IDictionary<string, string> parameters){
base.OnPushMessageClicked(context, parameters);
//Write code to process information
}
}
If you chose to define a custom MessageHandler
, you must declare it in your application on your AndroidManifest file as meta-data.
In order to do this, you need to retrieve the value associated to the name of the Android Callable Wrapper for your custom implementation.
The easiest way to get the value at runtime, is to implement the following code:
//import the namespace in your activity
using Android.Util;
//implement this code in one of the lifecycle method of your activity
Log.Debug("FA","The CustomMessageHandler name is : " + Java.Lang.Class.FromType(typeof(<ABSOLUTE_PATH_OF_THE_CLASS>.<NAME_OF_THE_CUSTOM_MESSAGE_HANDLER_CLASS>)).Name);
For instance:
Log.Debug("FA","The CustomMessageHandler name is : " + Java.Lang.Class.FromType(typeof(FollowAnalyticsSDK.Android.Sample.CustomMessageHandler)).Name);
This will output a similar result, at runtime, in the Logcat console:
FA D The CustomMessageHandler name is : md5dc1df9376dd70f35e4f0f156de0b2eea.CustomMessageHandler
Nothing appears in Logcat console
The problem can be due to the wrong absolute path or the activity that has not executed the line of code (wrong place). Consider to recheck your code.
Finally, copy the value and paste it to the attribute android:value
in your <meta-data> tag.
For instance:
<application>
[...]
<meta-data android:name="com.followanalytics.deeplinking.handler" android:value="md5dc1df9376dd70f35e4f0f156de0b2eea.CustomMessageHandler"/>
[...]
</application>
Don't change the attribute android:name
The content associated to the attribute android:name
must not be changed !
It is used by the FollowAnalytics SDK in order to find the customized class.
Consider to test those changes before removing the code which retrieves the value associated to the name of the Android Callable Wrapper.
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 application code, instead of being showed automatically by the SDK. The behavior is defined when creating the campaign, using the "automatically display content" switch.
iOS
For geofencing campaigns you need to enable geofence
FollowAnalytics.EnableGeofencing(true);
Pausing 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 app. 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 supposed to be displayed when the mechanism is paused, is stacked and shown as soon as the mechanism is resumed. This way you can send send in-app campaigns without impacting the user experience.
To prevent the SDK from displaying rich campaigns use the following method:
FollowAnalytics.InApp.PauseCampaignDisplay();
To resume the SDK from displaying rich campaigns use the following method:
FollowAnalytics.InApp.ResumeCampaignDisplay();
Tip: Use the lifecycle concepts from android to control campaigns.
To prevent the SDK from displaying the campaigns on a given activity, call the Pause method before the creation of an activity in order to block the campaigns.
Resume the campaigns by calling the Resume method on any other place of the application which will activate them.
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 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.
If you want to use Data Wallet, the very first step is to enable it in your app at startup. This is done by accessing the FollowAnalyticsConfiguration
object which contains the property isDataWalletEnabled
. Set this property to true
.
Policy download and consent
Now that the Data Wallet is enabled, the SDK will automatically download the new policies as they are published. In order to deal with the currently known policy, call the API with the following methods:
DataWallet.Policy policy = FollowAnalytics.DataWallet.GetPolicy(); // gets the current policy
BOOL policyIsRead = FollowAnalytics.DataWallet.isRead; // true if the current policy is considered accepted
FollowAnalytics.DataWallet.SetIsRead(true); // informs the SDK that the user has accepted the current policy
There could only be one active policy at a time. When a new policy becomes available online, the SDK will call on the main thread onDataWalletPolicyChange
, callback set on the FollowAnalyticsConfiguration
. To set this up before starting the SDK, include the following code:
iOS
FollowAnalytics.Configuration configuration = new FollowAnalytics.Configuration((obj) =>
{
...
obj.isDataWalletEnabled = true;
obj.onDataWalletPolicyChange = delegate () (optional)
{
};
});
Android
public class MyConfiguration : FollowAnalytics.Configuration
{
...
public override bool IsDataWalletEnabled()
{
return true;
}
public override void OnDataWalletPolicyChanged()
{
Application.Context.StartActivity(typeof(PolicyActivity));
}
}
At each major policy update, there needs to be consent from the client. When the user accepts a policy call [FollowAnalytics.dataWallet setIsRead:true]
to mark the current policy as "read". In other words:
- If
FollowAnalytics.DataWallet.isRead
isfalse
, the current policy major version has yet to be accepted by the user. - If the current policy is accepted,
FollowAnalytics.DataWallet.isRead
becomestrue
.
The SDK records the major version of the current policy for future reference. By default, if no other configuration is present, the SDK will return a default policy with version 0.0. This policy is always read. You should check for version 0.0 and handle it appropriately.
Custom default policy
If you want to provide a custom default policy for your users, download the policy JSON file from the back office and add it to your app, then modify the configuration to use it as follows:
iOS
FollowAnalytics.Configuration configuration = new FollowAnalytics.Configuration((obj) =>
{
obj.dataWalletDefaultPolicyPath = "YOUR_POLICY_PATH";
});
Android
public class MyConfiguration : FollowAnalytics.Configuration
{
...
public override string GetDefaultPolicyFilePath()
{
return "YOUR_POLICY_PATH";
}
}