Parsely Android Quickstart Guide¶
Integrating with Android Studio¶
To integrate Parse.ly mobile tracking with your Android Studio app:
- Copy the parselyandroid directory to your project’s top-level package directory (in a default Android Studio project, this is
/app/src/main/java/com.) The directory tree should look like/app/src/main/java/com/parsely/parselyandroid. - In
Build -> Edit Libraries and Dependenciesunder theDependenciestab, use the green + to add two Library Dependencies:org.codehaus.jackson:jackson-core-lgpl:1.9.13andorg.codehaus.jackson:jackson-mapper-lgpl:1.9.13 - Add the following lines to your
AndroidManifest.xmlfile:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- Add the following lines to
app/build.gradle:
packagingOptions {
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
Using the SDK¶
In any file that uses the Parsely SDK, be sure to add the line
import com.parsely.parselyandroid.*;
at the top of the file.
Before using the toolkit, you must initialize the Parsely object with your public api key. This is usually best to do in the MainActivity’s onCreate method.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ParselyTracker.sharedInstance("examplesite.com", this);
}
The this parameter is necessary to give Parsely access to the app’s context.
The Parsely toolkit maintains a queue of pageview events and periodically flushes it to the servers. This helps extend the battery life of your users’ Android devices. As a result of this design, there may be some pageview events remaining in the queue at the time the user exits your app. To make sure all of the queued events are flushed to the server at this time, make sure to include a call to flush() in your main activity’s onDestroy() method:
@Override
protected void onDestroy() {
ParselyTracker.sharedInstance().flush();
super.onDestroy();
}
To register a pageview event with Parsely, simply use the track call.
ParselyTracker.sharedInstance().trackURL("http://examplesite.com/something-whatever.html");
This call requires the canonical URL of the page corresponding to the post currently being viewed.