2012-11-03 58 views
2

我想報告安裝事件亂七八糟。我無法跟蹤谷歌播放的referrer_install

我已經實施了應用程序安裝時調用的ReferralReceiver。 我擁有地圖中的所有參數。 我用我的慌張代碼調用亂舞:

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

回答

0

我認爲亂碼在開始/結束會話之間有一段最短的秒數才能真正計數。您可以將所有數據保存到共享首選項或文件中,然後當用戶開始活動時檢查是否已給予亂舞。如果它是新的FlurryAgent.logEvent(...)。