For Unity-specific instructions, please visit https://github.com/Ordinance/tenjin-unity-sdk.
- Include
INTERNET
permissions within the manifest tags - Include Google Play Services within the application tags
- Include Tenjin's INSTALL_REFERRER receiver
<manifest>
...
<application ...>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
<receiver android:name="com.tenjin.android.TenjinReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
...
</application>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <!-- Required to get network connectivity (i.e. wifi vs. mobile) -->
...
</manifest>
- Download the latest Android SDK from here.
- Add the tenjin.jar into your Android Studio project by selecting New > Module.
- In the New Module dialog, select the Import .JAR or .AAR Package option and click on Next.
- Select the tenjin.jar file click on Finish.
- If you haven’t already installed the Google Play Services, add it to our build.gradle file.
dependencies {
compile 'com.google.android.gms:play-services:10.0.1'
}
- In your app module's build.gradle file, make sure to add this into the dependencies block:
dependencies {
compile project(":tenjin")
}
- Download the latest Android SDK from here.
- Create a folder
libs
in your project's root folder. - Copy the
tenjin.jar
file to thelibs
folder. - Right click on
tenjin.jar
and then selectBuild Path
->Add to Build Path
- This should create a folder called
Referenced Libraries
in your project
- Install Google's
Android Support Repository
,Android Support Library
,Google Play Services
andGoogle Repository
SDKs from the SDK Manager. Google outlines how to best configure this if you haven't already.
- Get your
API_KEY
from your Tenjin Organization tab. - In your main Activity include the Tenjin SDK with
import com.tenjin.android.TenjinSDK;
3a. For eachonResume
method of everyActivity
add the following line of code:
TenjinSDK.getInstance(this, "[API_KEY]").connect();
Or similarly here's an example of what the Activity
integration(s) should look like:
import com.tenjin.android.TenjinSDK;
public class TenjinDemo extends ActionBarActivity {
//...other callbacks are here
@Override
public void onResume() {
//standard code
super.onResume()
//Integrate TenjinSDK connect call
String apiKey = <API_KEY>; //You can potentially set this as a global variable too
TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
instance.connect();
//Your other code...
...
}
3b. Alternate initialization with Facebook (DO NOT USE 3a and 3b. You need to use only one.)
import com.facebook.applinks.AppLinkData;
import com.tenjin.android.TenjinSDK;
public class TenjinDemo extends ActionBarActivity {
//...other callbacks are here
@Override
public void onResume() {
//standard code
super.onResume()
//Integrate TenjinSDK connect call
String apiKey = <API_KEY>; //You can potentially set this as a global variable too
final TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
AppLinkData.fetchDeferredAppLinkData(this,
new AppLinkData.CompletionHandler() {
@Override
public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
if (appLinkData != null) {
String appLinkUri = appLinkData.getTargetUri().toString();
instance.connect(appLinkUri);
} else {
instance.connect();
}
}
}
);
//Your other code...
...
}
To understand user revenue and purchase behavior, developers can send transaction
events to Tenjin. There are two ways to send transaction
events to Tenjin.
- Validate receipts
Tenjin can validate
transaction
receipts for you. Visit your app on the dashboard (Apps -> Your Android App -> Edit) and enter your Public Key that can be found in your Google Play dashboard under "Services & APIs".
After entering your Public Key into the Tenjin dashboard for your app, you can use the Tenjin SDK method below:
public void transaction(String productId, String currencyCode, int quantity, double unitPrice, String purchaseData, String dataSignature)
Here's an example of this can be implemented at the time of purchase (ex. code taken from here http://developer.android.com/google/play/billing/billing_integrate.html#Purchase):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
//here you will need to assign the currencyCode, quantity, and the price
TenjinSDK.getInstance(this, API_KEY).transaction(sku, "USD", 1, 3.99, purchaseData, dataSignature)
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
- Pass the transaction manually (usually this is necessary if purchases are not handled by Google Play)
To send
transaction
events, you must provide theproductId
,currencyCode
,quantity
, andunitPrice
of the user's transaction following method signature below:
public void transaction(String productId, String currencyCode, int quantity, double unitPrice)
.
Here's an example of how this can be implemented at the time of purchase:
//The developer's own method for completing a transaction that happened in app
public void completeTransaction(String productId, String currencyCode, int quantity, double unitPrice){
...
//Call the Tenjin SDK with the context and the API_KEY
TenjinSDK.getInstance(this, API_KEY).transaction(productId, currencyCode, quantity, unitPrice);
...
}
productId
-> Name or ID of the product that you're sellingcurrencyCode
-> Currency code of the pricequantity
-> Number of transactions that you are doing on this eventunitPrice
-> Unit price of a single transaction
Tenjin will calculate the Total Revenue from a transaction based on quantity
*unitPrice
Tenjin will record and track the revenue based on the currency code, quantity, and the unit price sent.
You can use the Tenjin SDK to pass a custom event: eventWithName(String name)
.
The custom interactions with your app can be tied to level cost from each acquisition source that you use through Tenjin's service. Here is an example of usage:
String apiKey = <API_KEY>;
TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
//Integrate a custom event with a distinct name - ie. swiping right on the screen
instance.eventWithName("swipe_right");
NOTE: DO NOT SEND CUSTOM EVENTS BEFORE THE INITIALIZATION event (above). The initialization event must come before any custom events are sent.
You can use the Tenjin SDK to pass a custom event with an integer value: eventWithNameAndValue(String name, String value)
or eventWithNameAndValue(String name, int value)
.
Passing an integer value
with an event's name
allows marketers to sum up and track averages of the values passed for that metric in the Tenjin dashboard. If you plan to use DataVault, these values can be used to derive additional metrics that can be useful.
String apiKey = <API_KEY>;
TenjinSDK.instance = TenjinSDK.getInstance(this, apiKey);
//Integrate a custom event with a distinct name and value - ie. paying 100 virtual coins for an item
instance.eventWithNameAndValue("item", "100");
Using the example above, the Tenjin dashboard will sum and average the values for all events with the name item
.
Keep in mind that this event will not work if the value passed not an integer.
Tenjin supports the ability to direct users to a specific part of your app after a new attributed install via Tenjin's campaign tracking URLs. You can utilize the getDeeplink
method and callback to access the deferred deeplink through the data object. To test you can follow the instructions found here.
import com.tenjin.android.TenjinSDK;
public class TenjinDemo extends ActionBarActivity {
//...other callbacks are here
@Override
public void onResume() {
//standard code
super.onResume()
//Integrate TenjinSDK connect call
String apiKey = <API_KEY>; //You can potentially set this as a global variable too
TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
instance.connect();
instance.getDeeplink(new Callback() {
@Override
public void onSuccess(boolean clickedTenjinLink, boolean isFirstSession, Map<String, String> data) {
if (clickedTenjinLink) {
if (isFirstSession) {
if (data.containsKey(TenjinSDK.DEEPLINK_URL)) {
// use the deferred_deeplink_url to direct the user to a specific part of your app
}
}
}
}
});
//Your other code...
...
}
You can also use the v1.7.1+ SDK for handling post-install logic by checking the isFirstSession
param. For example, if you have a paid app, you can register your paid app install in the following way:
import com.tenjin.android.TenjinSDK;
public class TenjinDemo extends ActionBarActivity {
//...other callbacks are here
@Override
public void onResume() {
//standard code
super.onResume()
//Integrate TenjinSDK connect call
String apiKey = <API_KEY>; //You can potentially set this as a global variable too
TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
instance.connect();
instance.getDeeplink(new Callback() {
@Override
public void onSuccess(boolean clickedTenjinLink, boolean isFirstSession, Map<String, String> data) {
if (isFirstSession) {
// send paid app price and revenue to Tenjin
}
}
});
//Your other code...
...
}
To test the Android INSTALL_REFERRER
is working:
- Do the above initialization instrutions
- Open up your
./adb shell
. Ifadb
is not in your home directory locate it in your Android SDK folder - Run your app
- Filter for the
REF
tag in your IDE - Run and Test:
am broadcast -a com.android.vending.INSTALL_REFERRER -n <com.your.apppackage>/com.tenjin.android.TenjinReferrerReceiver --es "referrer" "ai=test&gclid=click_test"
After testing this you should see the output of the values passed to your referrer
in your IDE console. In the case above you would see:
ai=test&gclid=click_test