获取Google广告系列跟踪

时间:2013-03-19 10:49:49

标签: android google-analytics

Google Analytics正在使用utm_source,utm_campaign和utm_medium存储我在URL中传递的信息。现在我想知道当用户打开应用程序时我是如何获取该信息的?我在日志中看到了这一点:'

03-18 20:19:48.633: I/GAV2(32317): Thread[GAThread,5,main]: Campaign found: utm_source=source value tracking tara&utm_medium=medium value tracking tara&utm_campaign=campaign value tracking tara androidlitetrackingtara

我的应用程序清单中有这个:

<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />

        <receiver
            android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

我试图从意图中抓住它,但数据不存在。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

确保您使用的是v3 SDK。这是说明页面:

https://developers.google.com/analytics/devguides/collection/android/v3/campaigns

如果INTENT_REFERRER不起作用,请尝试稍后在页面中给出的Map示例。

此外,请确保您在下载应用和GA中显示的数据之间留出足够的时间。 GA可能需要约24小时才能显示数据。

答案 1 :(得分:0)

创建自己的广播接收器。存储数据并稍后将其传递给谷歌分析

public class InstallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Log.d("InstallReceiver", "onReceive");

    try {
        // get referrer value

        Bundle extras = intent.getExtras();
        if (extras != null) {

            GoogleAnalytics.getInstance(context).getLogger().setLogLevel(LogLevel.VERBOSE);
            String referrerValue = extras.getString("referrer");
// Handle data. Save it


            Log.d("InstallReceiver", "referrerValue=" + referrerValue);
            String afterDecode = URLDecoder.decode(referrerValue, "UTF-8");
            String[] temp = afterDecode.split("&");
            String agencyId = temp[0].replace("utm_source=", "");


            Utils.saveAgencyId(context.getApplicationContext(), agencyId);

// transfer intent to google receiver.


            new CampaignTrackingReceiver().onReceive(context, intent);
        }

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}