2

我正在尝试将安装事件报告为乱七八糟。

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

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

数据被存储到 SharedPreferences 但它没有被发送到flurry。

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

@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"
};
4

1 回答 1

0

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

于 2013-11-26T15:37:03.453 回答