我无法跟踪google play的referrer_install

时间:2012-11-03 15:19:35

标签: android install referrer flurry

我正在尝试将安装事件报告为乱舞。

我已经实现了在安装应用程序时调用的ReferralReceiver。 我在地图中有所有参数。 我用我的乱码代码叫Flurry:

FlurryAgent.onStartSession(context, FlurryCode);
FlurryAgent.logEvent("Referral", referralParams);
FlurryAgent.onEndSession(context);

数据存储在SharedPreferences中,但不会被发送到乱舞。

有没有人遇到过这个问题。

@Override
public void onReceive(Context context, Intent intent)
{
     LogManager.Info("ReferralReceiver intent.action=" + intent.getAction());
     LogManager.Info("ReferralReceiver intent.DataString=" + intent.getDataString());
     LogManager.Info("ReferralReceiver intent.intent=" + intent.toString());

    // Workaround for Android security issue: http://code.google.com/p/android/issues/detail?id=16006
    try
    {
        final Bundle extras = intent.getExtras();
        if (extras != null) {
            extras.containsKey(null);
        }
    }
    catch (final Exception e) {
        return;
    }

    Map<String, String> referralParams = new HashMap<String, String>();

    // Return if this is not the right intent.
    if (! intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) { //$NON-NLS-1$
        return;
    }

    String referrer = intent.getStringExtra("referrer"); //$NON-NLS-1$
    if( referrer == null || referrer.length() == 0) {
        return;
    }

    try 
    {
        referrer = URLDecoder.decode(referrer, "UTF-8");
    } 
    catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    LogManager.Info("ReferralReceiver intent.referrer=" + intent.getStringExtra("referrer"));

    SharedPreferences storage = context.getSharedPreferences(ReferralReceiver.PREFS_FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = storage.edit();
    editor.putString("referrer", referrer);
    editor.commit();

    try {
        if (intent.hasExtra("referrer")) {
            String referrers[] = referrer.split("&");
            for (String referrerValue : referrers) 
            {
                String keyValue[] = referrerValue.split("=");
                if (keyValue.length==2)
                {
                    referralParams.put(keyValue[0], keyValue[1]);
                }
            }
        }
    } 
    catch (Exception e) 
    {
        LogManager.Error(e);
        return;
    }

    ReferralReceiver.storeReferralParams(context, referralParams);

    String FlurryCode = SaverrUtils.GetFlurryCode();
    FlurryAgent.onStartSession(context, FlurryCode);
    FlurryAgent.logEvent("Referral", referralParams);
    FlurryAgent.onEndSession(context);
    LogManager.Info("New_Install");
}

public final static String PREFS_FILE_NAME = "ReferralParamsFile";


 /*
 * Stores the referral parameters in the app's sharedPreferences.
 * Rewrite this function and retrieveReferralParams() if a
 * different storage mechanism is preferred.
 */
public static void storeReferralParams(Context context, Map<String, String> params)
{
    SharedPreferences storage = context.getSharedPreferences(ReferralReceiver.PREFS_FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = storage.edit();

    for(String key : SaverrUtils.EXPECTED_REFERRER_PARAMETERS)
    {
        String value = params.get(key);
        if(value != null)
        {
            editor.putString(key, value);
        }
    }

    editor.commit();
}



// Referral Parameters
public final static String[] EXPECTED_REFERRER_PARAMETERS = {
    "utm_source",
    "utm_medium",
    "utm_term",
    "utm_content",
    "utm_campaign",
    "referrer"
};

1 个答案:

答案 0 :(得分:0)

我认为flurry在开始/结束会话之间的最小秒数才能实际计算。您可以将所有数据保存到共享首选项或文件,然后当用户启动您的活动时检查它是否已被赋予乱码。如果它是新的FlurryAgent.logEvent(...)。