[英]Google Analytics / campaign measurement
我無法理解Google Analytics(分析)中的一件事。 我需要在我的應用程序一個功能,例如,如果用戶是指我的應用程序B的用戶然后他得到了一些回報,但我想通過鏈接來追蹤用戶 ID當B用戶打的鏈接,然后我可以得到B的用戶應用程序的用戶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
gradle文件:
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。 我怎樣才能做到這一點
使用以下代碼創建一個廣播接收器:
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>
我還沒有嘗試過。 但是根據Google Analytics(分析)廣告系列跟蹤中提供的文檔。 以下代碼應在您的主要活動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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.