AppTrove Flutter SDK
Table of Content
Integration
- Quick start guide
- Integrate and Initialize the AppTrove SDK
- Events Tracking
- Track Uninstall for Android
- SDK Signing
- Deep linking
- Getting Campaign Data
- Dynamic Deeplinks
- Proguard Settings
Quick start guide
We have created an example app for the Flutter SDK integration.
Please check the Example directory to know how the AppTrove SDK can be integrated.
Add Flutter SDK to your app
Flutter SDK is very easy to integrate in your app. Just need to follow some steps
You can add the Flutter SDK in two ways:-
- By adding the below code in the package
pubspec.yaml
dependencies:
apptrove_sdk_flutter: ^2.0.0
- By using CLI command. You need to run the below command in
terminal/cmd.
$ flutter pub add apptrove_sdk_flutter
This command will directly add the AppTrove SDK to your package's pubspec.yaml.
After that run the below command to update the packages.
$ flutter packages get
Update Pod Dependencies
For iOS app make sure to go to ios folder and install Cocoapods dependencies:
$ cd ios && pod install
Adding Android install referrer to your app
Add the Android Install Referrer as a dependency in your app build.gradle . You can find the latest version here
dependencies {
// make sure to use the latest SDK version:
implementation 'com.android.installreferrer:installreferrer:2.2'
}
Add required permissions
AppTrove SDK needs the following below permission in the AndroidManifest.xml
Please add the below permission in your app project AndroidManifest.xml if they are not added.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional : -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Getting Google Advertising ID
AppTrove SDK needs the advertising id from the application.
For achieving this, you need to add some line of code in the build.gradle and also in AndroidManifest.xml for read the Advertising id from the application which is mentioned below:-
- Add the google advertising id dependency in your android/app/build.gradle
dependencies {
// This can be added where the SDK dependency has been added
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
}
- Update your Android Manifest file by adding the following permission. This is required if your app is targeting devices with android version 12+
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
- Add meta data inside the application tag (If not already added)
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> //Add this meta-data in the manifest.xml under Application tag.
Integrate and Initialize the AppTrove SDK
Retrieve your dev key
For initialising the AppTrove SDK. First, We need to generate the SDK key from the AppTrove MMP panel.
Following below are the steps to retrieve the development key:-
- Login your AppTrove Panel
- Select your application and click on Action button and login as
- In the Dashboard, Click on the
SDK Integrationoption on the left side of panel. - under on the SDK Integration, You will be get the SDK Key.
Integrate the AppTrove SDK in the Flutter Application.
Flutter SDK should be initialized in the initState() method under main.dart class.
Below are the example of initializing and calling the method of the SDK.
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
initializeSdk();
}
Future<void> initializeSdk() async {
String key ="xxxx-xx-4505-bc8b-xx"; //Please pass your Development key here.
/*While Initializing the SDK, You need to pass the two arguments in the ApptroveSDKConfig.
* In First argument, you need to pass the AppTrove SDK api key
* In second argument, you need to pass the environment which can be either "development", "production" or "testing". */
ApptroveSDKConfig apptroveSDKConfig = ApptroveSDKConfig(key, "production");
ApptroveFlutterSdk.initializeSDK(apptroveSDKConfig);
}
}
Important: it is crucial to use the correct dev key when initializing the SDK. Using the wrong dev key or an incorrect dev key impact all traffic sent from the SDK and cause attribution and reporting issues.
Events Tracking
AppTrove events tracking enables to provides the insights into how to user interacts with your app. AppTrove SDK easily gets that insights data from the app. Just follow with the simple events integration process
AppTrove provides the Built-in events and Customs events on the AppTrove panel.
Built-in Events -
Predefined events are the list of constants events which already been created on the dashboard.
You can use directly to track those events. Just need to implements events in the app projects.
Example code for calling Built-in events
/*
* Event Tracking
<------------->
* The below code is the example to pass a event to the AppTrove SDK.
* This event requires only 1 Parameter which is the Event ID.
* Below are the example of built-in events function calling
* The arguments - "ApptroveEvent.LOGIN" passed in the AppTrove event class is Events id
*
*/
void _eventsTracking(){
ApptroveEvent apptroveEvent = ApptroveEvent(ApptroveEvent.LOGIN);
/*Below are the function for the adding the extra data,
You can add the extra data like login details of user or anything you need.
We have 10 params to add data, Below 5 are mentioned*/
apptroveEvent.param1 = "param1";
apptroveEvent.param2 = "param2";
apptroveEvent.param3 = "param3";
apptroveEvent.param4 = "param4";
apptroveEvent.param5 = "param5";
apptroveEvent.setEventValue("ev1", "eventValue1");
apptroveEvent.setEventValue("ev2", 1);
ApptroveFlutterSdk.trackEvent(apptroveEvent);
}
Note:- Argument in ApptroveEvent class is event Id.
You can integrate inbuilt params with the event. In-built param list are mentioned below:-
orderId, revenue, currency, param1, param2, param3 ,param4, param5, param6, param7, param8, param9, param10.
Customs Events -
Customs events are created by user as per their required business logic.
You can create the events in the AppTrove dashboard and integrate those events in the app project.
Example code for calling Customs Events.
/*
* Event Tracking
<------------->
* The below code is the example to pass a event to the AppTrove SDK.
* This event requires only 1 Parameter which is the Event ID.
* Below are the example of customs events function calling for `AppOpen` event name.
* The arguments - "sEMWSCTXeu" passed in the ApptroveEvent class is Events id
*
*/
void _eventsTracking(){
ApptroveEvent apptroveEvent = ApptroveEvent("sEMWSCTXeu");
/*Below are the function for the adding the extra data,
You can add the extra data like login details of user or anything you need.
We have 10 params to add data, Below 5 are mentioned*/
apptroveEvent.param1 = "param1";
apptroveEvent.param2 = "param2";
apptroveEvent.param3 = "param3";
apptroveEvent.param4 = "param4";
apptroveEvent.param5 = "param5";
apptroveEvent.setEventValue("ev1", "eventValue1");
apptroveEvent.setEventValue("ev2", 1);
ApptroveFlutterSdk.trackEvent(apptroveEvent);
}
Revenue Event Tracking
AppTrove allows user to pass the revenue data which is generated from the app through Revenue events. It is mainly used to keep record of generating revenue from the app and also you can pass currency as well.
void _revenueEventsTracking(){
// Below are the example of revenue events function calling
//The arguments - "ApptroveEvent.LOGIN" passed in the event class is Events id
ApptroveEvent apptroveEvent = ApptroveEvent(ApptroveEvent.LOGIN);
//Passing the revenue events be like below example
apptroveEvent.revenue = 10.0; //Pass your generated revenue here.
apptroveEvent.currency = "INR"; //Pass your currency here.
apptroveEvent.orderId = "orderID";
apptroveEvent.param1 = "param1";
apptroveEvent.param2 = "param2";
apptroveEvent.setEventValue("ev1", "eventValue1");
apptroveEvent.setEventValue("ev2", 1);
ApptroveFlutterSdk.trackEvent(apptroveEvent);
}
Pass the custom params in events
void customParamTracking(){
// Below are the example of revenue events function calling
//The arguments - "ApptroveEvent.LOGIN" passed in the event class is Events id
ApptroveEvent apptroveEvent = ApptroveEvent(ApptroveEvent.LOGIN);
//Passing the custom params in events be like below example
var eventCustomParams = Map<String, Object>();
eventCustomParams={"name":"abcd"};
eventCustomParams={"age":"28"};
apptroveEvent.evMap=eventCustomParams;
ApptroveFlutterSdk.trackEvent(apptroveEvent);
}
- First create a map.
- Pass its reference to apptroveEvent.evMap param of event.
- Pass event reference to trackEvent method of ApptroveSDK.
Passing User Data to SDK
AppTrove allows to pass additional data like Userid, Email to SDK so that same can be correlated to the AppTrove Data and logs.
Just need to pass the data of User Id, Email Id and other additional data to AppTrove SDK function which is mentioned below:-
void userDetails(){
/*Passing the UserId and User EmailId Data */
ApptroveFlutterSdk.setUserId("XXXXXXXX"); //Pass the UserId values here
ApptroveFlutterSdk.setUserEmail("abc@gmail.com"); //Pass the user email id in the argument.
}
For Passing Additional Data
AppTrove allows for passing the additional user details like UserName, Mobile Number, UserAge, UserGender etc. You need to first make a hashmap and pass it in setUserAdditionalDetail function. The example are in mentioned below
void userDetails(){
/*Passing the UserId and User EmailId Data */
ApptroveFlutterSdk.setUserId("XXXXXXXX"); //Pass the UserId values here
ApptroveFlutterSdk.setUserEmail("abc@gmail.com"); //Pass the user email id in the argument.
/*Passing the additional data */
var userDetails = Map<String, Object>();
userDetails={"name":"abcd"}; //You can pass the Username data.
userDetails={"mobile_number":"872xxxxx87"}; // You can pass user mobile number
ApptroveFlutterSdk.setUserAdditionalDetail(userDetails);
}
Track Uninstall for Android
Before you begin
- Install
firebase_coreand add the initialization code to your app if you haven't already. - Add your app to your Firebase project in the Firebase console.
Add the Analytics SDK to your app
-
From the root of your Flutter project, run the following command to install the plugin:
flutter pub add firebase_analytics -
Once complete, rebuild your Flutter application:
flutter run -
Once installed, you can access the
firebase_analyticsplugin by importing it in your Dart code:import 'package:firebase_analytics/firebase_analytics.dart'; -
Create a new Firebase Analytics instance by calling the
instancegetter onFirebaseAnalytics:FirebaseAnalytics analytics = FirebaseAnalytics.instance; -
Use the
analyticsinstance obtained above to set the following user property:var apptroveId = await ApptroveFlutterSdk.getApptroveId(); analytics.setUserProperty(name: "ct_objectId", value: apptroveId); -
Adding the above code to your app sets up a common identifier.
-
Set the
app_removeevent as a conversion event in Firebase. -
Use the Firebase cloud function to send uninstall information to AppTrove MMP.
SDK Signing
Following below are the steps to retrieve the secretId and secretKey :-
- Login your AppTrove Panel and select your application.
- In the Dashboard, click on the
SDK Integrationoption on the left side of panel. - Under on the SDK Integration, click on the Advanced tab.
- Under the Advanced tab, you will get the secretId and secretKey.
Check below the example code for passing the secretId and secretKey to the SDK
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
initializeSdk();
}
Future<void> initializeSdk() async {
String key ="xxxx-xx-4505-bc8b-xx"; //Please pass your Development key here.
/*While Initializing the SDK, You need to pass the two arguments in the ApptroveSDKConfig.
* In First argument, you need to pass the AppTrove SDK api key
* In second argument, you need to pass the environment which can be either "development", "production" or "testing". */
ApptroveSDKConfig apptroveSDKConfig = ApptroveSDKConfig(key, "production");
apptroveSDKConfig.setAppSecret("xxx", "xxx-xx");
ApptroveFlutterSdk.initializeSDK(apptroveSDKConfig);
}
}
Deep linking
Deep linking is a technique in which the user directly redirects to the specific pages of the application by clicking on the deeplink url.
There are two types of deeplinking
-
Normal deeplinking - Direct deep linking occurs when a user already has your app installed on their device. When this is the case, the deep link will redirect the user to the screen specified in the link.
-
Deferred deeplinking - Deferred deep linking occurs when a user does not have your app installed on their device. When this is the case, the deep link will first send the user to the device app store to install the app. Once the user has installed and opened the app, the SDK will redirect them to the screen specified in the link.
Normal Deep linking
If a user already has your app on their device, it will open when they interact with a tracker containing a deep link. You can then parse the deep link information for further use. To do this, you need to choose a desired unique scheme name.
You can set up a specific activity to launch when a user interacts with a deep link. To do this:
- Assign the unique scheme name to the activity in your AndroidManifest.xml file.
- Add the intent-filter section to the activity definition.
- Assign an android:scheme property value with your preferred scheme name.
For example, you could set up an activity called FirstActivity to open like this:
AndroidManifest.xml
<activity
android:name=".Activity.FirstProduct"
android:exported="true">
<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="apptrove.u9ilnk.me"
android:pathPrefix="/product"
android:scheme="https" />
</intent-filter>
</activity>
https://apptrove.u9ilnk.me/product?dlv=FirstProduct&quantity=10&pid=sms
Deferred Deep linking
Deferred deep linking happens when a user does not have your app installed on their device. When the user clicks an AppTrove URL, the URL will redirect them to the Play Store to download and install your app. When the user opens the app for the first time, the SDK will read the deep_link content.
The AppTrove SDK opens the deferred deep link by default. Just need to add some code in application class just after initialization of AppTrove SDK
Below are the example of the code :-
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
ApptroveSDKConfig apptroveSDKConfig = new ApptroveSDKConfig(
"0455721b-xxxx-xxxx-xxxx-596d818d910a", "development");
//Getting deeplink data from the below method
apptroveSDKConfig.deferredDeeplinkCallback = (uri){
print('The value of deeplinkUrl is: $uri');
};
ApptroveFlutterSdk.initializeSDK(apptroveSDKConfig);
}
Dynamic Deeplinks
We have added support for creating dynamic deep links using Flutter on both Android and iOS platforms. To generate a dynamic deep link, you need to call the following Dart function from your code:
ApptroveFlutterSdk.createDynamicLink(
templateId: 'wy23Px',
link: 'https://apptrove58.u9ilnk.me',
domainUriPrefix: 'apptrove58.u9ilnk.me',
deepLinkValue: 'CakeActivity',
androidRedirect: 'https://play.google.com/store/apps/details?id=com.apptrove.vistmarket',
sdkParameters: {
'product_id': 'chocochip',
'quantity': '2',
},
attributionParameters: {
'channel': 'my_channel',
'media_source': 'at_invite',
'campaign': 'sanu',
},
iosRedirect: 'https://www.example.com/ios',
desktopRedirect: 'https://apptrove.com',
socialMeta: {
'title': 'Your Title',
'description': 'Your Description',
'imageLink': 'https://www.example.com/image.jpg',
},
).then((url) {
// Success callback
print('Deep Link URL: $url');
}).catchError((err) {
// Error callback
print('Failed to create link: $err');
});
Getting Campaign Data
For getting the campaign data, We have a function that returns the campaign data. Please check below the example code.
_gettingCampaignData() {
ApptroveEvent apptroveEvent = new ApptroveEvent("1CFfUn3xEY");
var ad = await ApptroveFlutterSdk.getAd();
var getAdID = await ApptroveFlutterSdk.getAdID();
var getCampaign = await ApptroveFlutterSdk.getCampaign();
var getCampaignID = await ApptroveFlutterSdk.getCampaignID();
var getAdSet = await ApptroveFlutterSdk.getAdSet();
var getAdSetID = await ApptroveFlutterSdk.getAdSetID();
var getP1 = await ApptroveFlutterSdk.getP1();
var getP2 = await ApptroveFlutterSdk.getP2();
var getP3 = await ApptroveFlutterSdk.getP3();
var getP4 = await ApptroveFlutterSdk.getP4();
var getP5 = await ApptroveFlutterSdk.getP5();
var getClickId = await ApptroveFlutterSdk.getClickId();
var getDlv = await ApptroveFlutterSdk.getDlv();
var getPid = await ApptroveFlutterSdk.getPid();
var getIsRetargeting = await ApptroveFlutterSdk.getIsRetargeting();
ApptroveFlutterSdk.trackEvent(apptroveEvent);
}
Proguard Settings
If your app is using proguard then add these lines to the proguard config file
-keep class com.apptrove.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }