0

如何在 android 中使用 mixpanel 分析进行推荐跟踪。我用谷歌搜索了它,我无法得到任何正确的答案。

4

1 回答 1

3

首先你必须编写一个广播接收器来接收推荐意图

public class ReferalIntentReciever extends BroadcastReceiver {
    public static MixpanelAPI mixpanel;

    Context context;

    @Override
    public void onReceive(Context context, Intent intent) {
        mixpanel = MixpanelAPI.getInstance(context, "YOUR MIXPANEL TOKEN");

        // TODO Auto-generated method stub

        String referrerString = intent.getStringExtra("referrer");
       //sending to mixpanel
        try {
            JSONObject props = new JSONObject();
            props.put("utm_source", splitQuery(referrerString)
                    .get("utm_source"));
            props.put("utm_medium", splitQuery(referrerString)
                    .get("utm_medium"));
            if (splitQuery(referrerString).get("utm_campaign") != null) {
                props.put("utm_campaign",
                        splitQuery(referrerString).get("utm_campaign"));
            }
            mixpanel.track("Referral Campaign", props);
            mixpanel.flush();

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    //getting each parameter 

    public static Map<String, String> splitQuery(String url)
            throws UnsupportedEncodingException {
        Map<String, String> query_pairs = new LinkedHashMap<String, String>();
        String[] pairs = url.split("&");
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"),
                    URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
        }
        return query_pairs;
    }
}

并在清单中设置接收器

<receiver
            android:name=".ReferalIntentReciever"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver> 

还要检查这个 没有谷歌分析实施安卓的谷歌播放活动跟踪

于 2014-09-25T07:41:27.400 回答