Android Attribution SDK

vNative Attribution SDK

(Current Version : 1.6)

To Download Attribution SDK aar file, click here

Requirements

  • Android API 15 (min).
  • Security Token provided in vNative Dashboard.

Setup

1. Import AAR in your android studio project.
  • Add vtlib-release.aar file inside <APP_ROOT_FOLDER>/libs/ directory.
  • Add the following code inside build.gradle (Project level)
flatDir{
     dirs 'libs'
}

inside allProjects{…} code block like this

allprojects {
    repositories {
        jcenter()
        flatDir{
            dirs 'libs'
        }
    }
}
  • Now add following code in dependencies code block in build.gradle (:app)
compile(name: 'vtlib-release', ext: 'aar')

Stackoverflow : For more info click on the link

2. Set the Required Permissions

The AndroidManifest.xml should include the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Note : All these permissions are necessary in order for the SDK to work properly.

3. Add SECURITY_TOKEN in a <meta-data> tag inside <application> tag in AndroidManifest.xml file
<meta-data
    android:name="VNATIVE_SECURITY_TOKEN"
    android:value="YOUR_SECURITY_TOKEN" />

Note: Replace YOUR_SECURITY_TOKEN with the security token provided in your vNative Dashboard.

4. Set an Install Referrer Broadcast Receiver in AndroidManifest.xml

Android apps cannot have multiple receivers with the same intent-filtered action.

The following two options are available for implementing the install referrer broadcast receiver:

  • 4.1 Using a Multiple Broadcast Receiver

vNative Attribution SDK provides a solution that broadcasts INSTALL_REFERRER to all other receivers automatically. In the AndroidManifest.xml, add the following receiver as the FIRST receiver for INSTALL_REFERRER, and ensure the receiver tag is within the application tag:

<receiver
    android:name="com.vnative.vtlib.MultipleInstallBroadcastReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

If you want to use multiple receivers, the Manifest.xml must appear, as follows:

<!—The vNative Install Receiver is first and will broadcast to all receivers placed below it -->
<receiver
    android:name="com.vnative.vtlib.MultipleInstallBroadcastReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

<!—All other receivers should follow right after -->     
<receiver android:name="com.google.android.apps.analytics.AnalyticsReceiver" android:exported="true">
 <intent-filter>
      <action android:name="com.android.vending.INSTALL_REFERRER" />
 </intent-filter>
</receiver>

<receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true">
      <intent-filter>
          <action android:name="com.android.vending.INSTALL_REFERRER" />
      </intent-filter>
</receiver>
  • 4.2 Using a Single Broadcast Receiver

In the AndroidManifest.xml, add the following receiver as the FIRST receiver for INSTALL_REFERRER or after another multiple broadcast receiver, and ensure the receiver tag is within the application tag:

<receiver
    android:name="com.vnative.vtlib.SingleInstallBroadcastReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

AndroidManifest.xml will look like this after above configurations.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.package.name">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="VNATIVE_SECURITY_TOKEN"
            android:value="YOUR_SECURITY_TOKEN" />

        <receiver
            android:name="com.vnative.vtlib.SingleInstallBroadcastReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

        <activity
            .
            .
            .
            .
            Your activity tags
        </activity>

    </application>

</manifest>

Usage

– SDK Initialisation

Add the following line in your Main Activity onCreate() method (Not Splash Activity Screen).

VTLib.getInstance().init(this);
– Goals setup

Add the following code to send goal status after the goal is successfully accomplished.

VTLib.getInstance().trackInAppEvent(<Context>, <GOAL_ID>);

or

VTLib.getInstance().trackInAppEvent(<Context>, <GOAL_ID>, <TRANSACTION_ID>, <RATE>, <CURRENCY>);

Note : Replace GOAL_ID, TRANSACTION_ID, RATE, CURRENCY with the actual values and all these parameters are of type String.

Testing

  • Generate a click id from vNative Dashboard. (Note: Once click id used it will not work for the next time)
  • Open terminal and type
cd /Users/<YOUR_CURRENT_USER>/Library/Android/sdk/platform-tools/

Note this above is for mac users for linux and windows navigate to your platform-tools directory inside android-sdk folder.

  • Now paste the following in terminal.
echo 'am broadcast \
-a com.android.vending.INSTALL_REFERRER \
-n "your.package.name/com.vnative.vtlib.SingleInstallBroadcastReceiver" \
  --es "referrer" \
"utm_source%3D59439c6bed6f54128b214ac0%26vnclick_id=VNCLICK_ID";
exit' | ./adb shell

Note : Replace VNCLICK_ID with actual click id. If you are using MultipleInstallBroadcastReceiver then replace SingleInstallBroadcastReceiver with MultipleInstallBroadcastReceiver in the above command. Also replace your.package.name with your application package name.

  • Press enter, the SDK install track is successful. Now go to Server Logs > Conversions in vNative Dashboard, it will show your app install track detail.

Create Your Account Now!

Get Started for FREE Account with 5,000 Events per month. No credit card required.

Get Started FREE