-1

我无法理解Google Analytics中的一件事。我的应用程序中需要一个功能,例如如果A用户将我的应用程序推荐给B用户,那么他会获得一些奖励,但我想在B用户点击该链接时通过链接跟踪A用户 ID ,然后我可以在B用户应用程序中获取A用户 ID第一个活动。

我已生成此链接作为示例:https ://play.google.com/store/apps/details?id=com.example.app&referrer=utm_source%3Dgoogle%26utm_medium%3Demail%26utm_term%3Dtesting%26utm_content%3Dcontent%26utm_campaign %3Dglobus

毕业文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services-analytics:10.2.4'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

分析类:

public class AnalyticsApplication  extends Application {

    private static GoogleAnalytics sAnalytics;
    private static Tracker sTracker;

    @Override
    public void onCreate() {
        super.onCreate();

        sAnalytics = GoogleAnalytics.getInstance(this);
    }

    /**
     * Gets the default {@link Tracker} for this {@link Application}.
     * @return tracker
     */
    synchronized public Tracker getDefaultTracker() {
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        if (sTracker == null) {
            sTracker = sAnalytics.newTracker(R.xml.global_tracker);
        }

        return sTracker;
    }
}

此链接引用的所有类和代码: https ://developers.google.com/analytics/devguides/collection/android/v4/

现在我想跟踪用户 ID。我怎样才能做到这一点

4

2 回答 2

1

使用以下代码创建广播接收器:

public class CampaignBroadCastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
       String referrer= intent.getExtras().getString("referrer", ""); //your referrer
       new com.google.android.gms.analytics.CampaignTrackingReceiver().onReceive(context, intent); //update the same to Google Analytics  
    }
}

在您的清单中:

     <service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
     <receiver android:name="yourpackage.CampaignBroadCastReceiver">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
     </receiver>
于 2018-10-09T11:30:18.353 回答
0

我还没试过这个。但根据 Google Analytics Campaign Tracking 上提供的文档。以下代码应该在您的主要活动 onCreate 或 onStart 中工作

// Get the intent that started this Activity.
Intent intent = this.getIntent();
Uri uri = intent.getData();
String campaign = uri.getQueryParameter("utm_source");

并在清单文件中添加接收器以从 Play 商店获取 INSTALL_REFERRER 广播

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

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

于 2018-10-09T08:44:06.783 回答