Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko;
8 import org.json.JSONException;
9 import org.json.JSONObject;
11 import android.content.BroadcastReceiver;
12 import android.content.Context;
13 import android.content.Intent;
14 import android.util.Log;
16 import java.net.URLDecoder;
17 import java.util.HashMap;
19 public class ReferrerReceiver
20 extends BroadcastReceiver
21 {
22 private static final String LOGTAG = "GeckoReferrerReceiver";
24 public static final String ACTION_INSTALL_REFERRER = "com.android.vending.INSTALL_REFERRER";
25 public static final String UTM_SOURCE = "mozilla";
27 @Override
28 public void onReceive(Context context, Intent intent) {
29 if (ACTION_INSTALL_REFERRER.equals(intent.getAction())) {
30 String referrer = intent.getStringExtra("referrer");
31 if (referrer == null)
32 return;
34 HashMap<String, String> values = new HashMap<String, String>();
35 try {
36 String referrers[] = referrer.split("&");
37 for (String referrerValue : referrers) {
38 String keyValue[] = referrerValue.split("=");
39 values.put(URLDecoder.decode(keyValue[0]), URLDecoder.decode(keyValue[1]));
40 }
41 } catch (Exception e) {
42 }
44 String source = values.get("utm_source");
45 String campaign = values.get("utm_campaign");
47 if (source != null && UTM_SOURCE.equals(source) && campaign != null) {
48 try {
49 JSONObject data = new JSONObject();
50 data.put("id", "playstore");
51 data.put("version", campaign);
53 // Try to make sure the prefs are written as a group
54 GeckoEvent event = GeckoEvent.createBroadcastEvent("Campaign:Set", data.toString());
55 GeckoAppShell.sendEventToGecko(event);
56 } catch (JSONException e) {
57 Log.e(LOGTAG, "Error setting distribution", e);
58 }
59 }
60 }
61 }
62 }