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