[英]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.