Skip to content

phunware/maas-analytics-android-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phunware Analytics SDK for Android

Nexus

Phunware's Analytics SDK for Android. Visit https://www.phunware.com/ for more information or sign into the MaaS Portal to set up MaaS.

Requirements

  • minSdk 23.
  • AndroidX.

Download

Add the following repository to your top level build.gradle file:

repositories {
    maven {
        url "https://nexus.phunware.com/content/groups/public/"
    }
}

Add the following dependency to your app level build.gradle file:

dependencies {
    implementation "com.phunware.analytics:analytics-sdk:<version>"
}

Android project setup

Keys

To use any of the Phunware MaaS SDKs you'll need to add the following entries to your AndroidManifest.xml, making sure to replace the value properties with your actual App ID and Access Key:

<meta-data
    android:name="com.phunware.maas.APPLICATION_ID"
    android:value="YOUR_APP_ID"/>

<meta-data
    android:name="com.phunware.maas.ACCESS_KEY"
    android:value="YOUR_ACCESS_KEY"/>

For instructions on how to obtain an App ID and an Access key, please see the MaaS Setup section below.

Permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Usage

Initializing the SDK
Analytics.init(applicationContext: Context)
Sending events

After initializing the SDK, it's ready to send analytic events to MaaS. You can send events by simply calling:

Analytics.sendEvent(eventName: String)

You can also send parameters with your events:

Analytics.sendEvent(eventName: String, parameters: Map<String, Any>)

The parameter map accepts a String as the key for the parameter and Any as the value. You can pass any object as a parameter value, but you need to make sure it's Serializable.

Enabling automatic screen view tracking

If you want the Analytics SDK to automatically track how much time your users spend on each screen, call:

Analytics.enableAutomaticScreenViewEvents(true)

If you want to disable this feature, just call the same method with false:

Analytics.enableAutomaticScreenViewEvents(false)
Manually tracking screen view events

If you want to manually track your screen view events, call the following method when the user starts to see your screen:

Analytics.startScreenView(className: String, screenName: String, appSection: String?, customParams: Map<String, String>?)

And the following method when the user moves away from that screen:

Analytics.endScreenView(screenName: String)
Enabling location tracking

Some info cannot be tracked without first notifying the user about it, like tracking the user's location. If you'd like that information to be included in your analytic events, show a message explaining to your user why you need that information and only enable tracking after it has been acknowledged by your user.

To include user location data in your analytic events, call:

AnalyticsSettings.setLocationAccessEnabled(enabled: Boolean)

You're all set to send analytic events from your App!

Privacy

You understand and consent to Phunware’s Privacy Policy located at www.phunware.com/privacy. If your use of Phunware’s software requires a Privacy Policy of your own, you also agree to include the terms of Phunware’s Privacy Policy in your Privacy Policy to your end users.

Terms

Use of this software requires review and acceptance of our terms and conditions for developer use located at http://www.phunware.com/terms/