Skip to content
Browse files

Merge

  • Loading branch information...
2 parents 9beac22 + 47bb416 commit e5d798c64f636baaac1fabb540ce99b21add595f @daggerrz daggerrz committed
View
13 event-tracking/src/main/java/com/tapad/tracking/Event.java
@@ -1,19 +1,28 @@
package com.tapad.tracking;
/**
- * A wrapper for all event information. As of now, just an id.
+ * A wrapper for all event information.
*/
class Event {
private String id;
+ private String extraParameters;
- protected Event(String id) {
+ protected Event(String id, String extraParameters) {
this.id = id;
+ this.extraParameters = extraParameters;
+ }
+ protected Event(String id) {
+ this(id, null);
}
public String getId() {
return id;
}
+ public String getExtraParameters() {
+ return extraParameters;
+ }
+
@Override
public String toString() {
return "Event[id=" + id + "]";
View
3 event-tracking/src/main/java/com/tapad/tracking/EventResource.java
@@ -29,6 +29,7 @@
class EventResource {
private static final String RESOURCE_URL = "http://analytics.tapad.com/app/event";
private static final String PARAM_APP_ID = "app_id";
+ private static final String PARAM_EXTRA_PARAMS = "extra_params";
private static final String PARAM_DEVICE_ID = "device_id";
private static final String PARAM_EVENT_ID = "action_id";
@@ -54,6 +55,8 @@ protected void post(Event e) throws IOException {
params.add(new BasicNameValuePair(PARAM_APP_ID, appId));
params.add(new BasicNameValuePair(PARAM_DEVICE_ID, deviceId));
params.add(new BasicNameValuePair(PARAM_EVENT_ID, e.getId()));
+ if (e.getExtraParameters() != null)
+ params.add(new BasicNameValuePair(PARAM_EXTRA_PARAMS, e.getExtraParameters()));
String query = URLEncodedUtils.format(params, "UTF-8");
String uri = RESOURCE_URL + "?" + query;
View
28 event-tracking/src/main/java/com/tapad/tracking/InstallReferrerReceiver.java
@@ -0,0 +1,28 @@
+package com.tapad.tracking;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import com.tapad.util.Logging;
+
+/**
+ * Install referrer broadcast receiver for campaign tracking.
+ * <p/>
+ * <receiver android:name="com.tapad.tracking.InstallReferrerReceiver" android:exported="true">
+ * <intent-filter>
+ * <action android:name="com.android.vending.INSTALL_REFERRER" />
+ * </intent-filter>
+ * </receiver>
+ */
+public class InstallReferrerReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Bundle extras = intent.getExtras();
+ String referrerString = extras.getString("referrer");
+
+ Logging.info(getClass().getSimpleName(), "Referrer was " + referrerString);
+
+ Tracking.registerReferral(context, referrerString);
+ }
+}
View
48 event-tracking/src/main/java/com/tapad/tracking/Tracking.java
@@ -15,30 +15,13 @@
private static String deviceId;
/**
- * Initializes the tracking API using the app package name as the id.
+ * Initialize event tracking service.
*
- * One of the initialization functions must be called before TrackingService.get().
- *
- * @param context
+ * @return true if this is the first run
*/
- public static void init(Context context) {
- init(context, null);
- }
-
-
- /**
- * Initializes the tracking API using the supplied value as the application id. If the
- * supplied value is null or consist only of white space, then the app package name is
- * used.
- *
- * One of the initialization functions must be called before TrackingService.get().
- *
- * @param context
- * @param appId the application identifier
- */
- public static void init(Context context, String appId) {
+ private static boolean initialize(Context context, String appId) {
if (appId == null || appId.trim().length() == 0) {
- appId = context.getApplicationContext().getPackageName();
+ appId = context.getApplicationContext().getPackageName();
}
deviceId = PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_TAPAD_DEVICE_ID, null);
@@ -49,8 +32,29 @@ public static void init(Context context, String appId) {
}
service = new TrackingServiceImpl(new EventDispatcher(new EventResource(appId, deviceId)));
+ return firstRun;
+ }
- if (firstRun) {
+ /**
+ * Initializes the tracking API and a referral string.
+ * Must be called before TrackingService.get().
+ */
+ public static void registerReferral(Context context, String referrerString) {
+ initialize(context, null);
+ service.onEvent("install-referral", referrerString);
+ }
+
+ /**
+ * Initializes the tracking API using the supplied value as the application id.
+ * <p/>
+ * <p/>
+ * One of the initialization functions must be called before TrackingService.get().
+ *
+ * @param context
+ * @param appId the application identifier
+ */
+ public static void init(Context context, String appId) {
+ if (initialize(context, appId)) {
service.onEvent("install");
}
}
View
11 event-tracking/src/main/java/com/tapad/tracking/TrackingService.java
@@ -23,4 +23,15 @@
* @param eventId the id of the event, either one of the predefined constants, or developer specific ones
*/
void onEvent(String eventId);
+
+
+ /**
+ * Registers the specified event with the Tapad event tracking service. The
+ * actual event dispatch is done asynchronously, so this method will never
+ * block.
+ *
+ * @param eventId the id of the event, either one of the predefined constants, or developer specific ones
+ * @param extraParameters an opaque string og extra parameters that will be sent til the event tracking service
+ */
+ void onEvent(String eventId, String extraParameters);
}
View
4 event-tracking/src/main/java/com/tapad/tracking/TrackingServiceImpl.java
@@ -14,4 +14,8 @@ protected TrackingServiceImpl(EventDispatcher dispatcher) {
public void onEvent(String eventId) {
dispatcher.dispatch(new Event(eventId));
}
+
+ public void onEvent(String eventId, String extraParameters) {
+ dispatcher.dispatch(new Event(eventId, extraParameters));
+ }
}
View
2 event-tracking/src/main/java/com/tapad/util/Logging.java
@@ -3,7 +3,7 @@
import android.util.Log;
public class Logging {
- private static final boolean enabled = false;
+ private static final boolean enabled = true;
public static void info(String tag, String message) {
if (enabled) Log.i(tag, message);
View
24 sample-app/AndroidManifest.xml
@@ -1,18 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.tapad.sample"
- android:versionCode="1"
- android:versionName="1.0">
+ package="com.tapad.sample"
+ android:versionCode="5"
+ android:versionName="1.1">
+ <uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
- <application android:label="@string/app_name">
+ <application
+ android:icon="@drawable/logo"
+ android:label="TestApp"
+ >
<activity android:name=".MainActivity"
- android:label="@string/app_name">
+ android:label="TestActivity">
<intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+ <receiver android:name="com.tapad.tracking.InstallReferrerReceiver" android:exported="true">
+ <intent-filter>
+ <action android:name="com.android.vending.INSTALL_REFERRER"/>
+ </intent-filter>
+ </receiver>
<activity android:name=".AdViewActivity" android:label="Ad with managed view"/>
<activity android:name=".ManualMarkupActivity" android:label="Manual markup management"/>
</application>
+
</manifest>

0 comments on commit e5d798c

Please sign in to comment.
Something went wrong with that request. Please try again.