Install Android Sdk
This page will give detailed description of how you can integrate Growlytics android SDK to your native android app.
Use Growlytics Android SDK to track, analyze and engage user from native android apps.
Follow the guidelines to install the Growlytics Android SDK, track events, and see the event data within the Growlytics dashboard.
Add
growlytics-android-sdk
dependency to your project.For enable FCM support, you will need to add follwoing dependencies in your application’s
build.gradle
file. You will also have to add the FCM generated google-services.json file to your project.build.grdle
{
dependencies {
implementation 'com.growlytics.android.sdk:growlytic-android-sdk:1.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.3'
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.android.support:support-v4:28.0.0'
}
// at the end of the build.gradle file
apply plugin: 'com.google.gms.google-services'
}
Once you have added dependencies on your
build.gradle
file, sync your project by clicking on Tools > Android > Sync Project With Gradle Files
button.To send data to your Growlytics account, you will need to add your Growlytics account's credentials in the
AndroidManifest.xml
file in your application.As shown in snippet below, add your Growlytics project id and api key to your
AndroidManifest.xml
, within the tags.AndroidManifest.xml
<!-- Growlytics Project Id -->
<meta-data
android:name="GROWLYTICS_PROJECT_ID"
android:value="Growlytics Project Id"/>
<!-- Growlytics API Key -->
<meta-data
android:name="GROWLYTICS_API_KEY"
android:value="Growlytics Project Api Key"/>
<!-- Growlytics Project Env - Used for debugging integration -->
<meta-data
android:name="GROWLYTICS_ENV"
android:value="production"/>
<!-- Growlytics Enable/Disable - Enbled by default if not provided-->
<meta-data
android:name="GROWLYTICS_DISABLED"
android:value="1"/>
At the root of your manifest file inside <manifest> file, add following permissions.
AndroidManifest.xml
<!-- Required to allow the app to send events and user profile information -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Recommended so that Growlytics knows when to attempt a network call -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
In your AndroidManifest.xml file, add the following snippet within the tags.
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:name="com.growlytics.android.sdk.Application">
Make sure you have specified
android:name
as com.growlytics.android.sdk.Application.
Build and run your application.
Open your Growlytics dashboard. Goto People > Customers. If you successfully integrated the Growlytics SDK, you will see a new customer there.
An Event is an action that user takes in your mobile or web app. Growlytics records the event on the User Profile, using an Event Name and optional associated key:value-based Event Properties. You can then segment users, target and personalize messaging based on both the Event Name and specific Event Properties.
// Prepare Attributes
Map<String, Object> eventDetails = new HashMap<>();
eventDetails.put("Product Name", "Mens Polo T-shirt with Collor, Yellow");
eventDetails.put("Category", "Mens Accessories");
eventDetails.put("Sub Category", "Polo T-shirts");
eventDetails.put("Price", 999.99);
eventDetails.put("Date", new java.util.Date());
// Put them in growlytics user profile
Analytics.getInstance(this).track("Product Viewed", eventDetails);
A User is automatically created in Growlytics platrorm when user opens the app first time.
Initially, there are very few properties captured for User Profile like city, country, device info etc. Depending on your product purpose, You can add more information to user profile with
Analytics.identify()
method. There are two ways you can do this
- 1.If your customer has logged in with your system's user id, then you can pass customer's id which is in your system. This will help you keeping unified profile across web, mobile and other platforms. An example is given below.// Prepare AttributesMap<String, Object> userAttributes = new HashMap<>();attributes.put("has_subscribed", true);attributes.put("total_cart_visits", 12);// Put them in growlytics user profileAnalytics.getInstance(this).identify(userAttributes);
- 2.Another way, if user has not logged in yet but you still want to keep information as anonymous user, you can do that as well. An example is given below.// Prepare AttributesMap<String, Object> userAttributes = new HashMap<>();attributes.put("has_subscribed", true);attributes.put("total_cart_visits", 12);// Put them in growlytics user profileAnalytics.getInstance(this).identify(userAttributes);
Last modified 3yr ago