We have an Android app we'd like to track pages using Google Analytics with. I've integrated the Google Analytics SDK through Play Services 17.0.0.
However, a requirement is to merge the data with our site data. This means that "screen views" must also show up as "page views" in our "All Site Data" view on our Google Analytics account as well as "All App Data". This is because we'd like to see all data combined as one when looking at it, and not have to do double the work in aggregating it each time.
I was able to get page paths to show on our content view by setting tracker.setPage("/article/example-slug")
and then sending it as a screen view.
tracker.setPage(page)
tracker.setScreenName(screen)
tracker.setTitle(title)
tracker.send(HitBuilders.ScreenViewBuilder().build())
The problem is that it doesn't actually count them as "page views". This is what we see:
Looking at them in App View works correctly:
Again, we just want to be able to group app page views into site page views.
How can we make sure Google Analytics tracks page views correctly in our native Android app?
Add firebase into your project after
App Gradle
add dependency
dependencies {
implementation "com.google.firebase:firebase-analytics:17.1.0"
}
Project gradle
add this
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.0'
}
}
Add into your Activity
public class myClass extends AppCompatActivity implements View.OnClickListener {
public static FirebaseAnalytics mFirebaseAnalytics;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
}
@Override
public void onClick(View controlView) {
switch (controlView.getId()) {
case R.id.button1:
Bundle bundle = new Bundle();
bundle.putString("button1", "click");
mFirebaseAnalytics.logEvent("NormalUserclick", bundle);
break;
case R.id.button2:
Bundle bundle2 = new Bundle();
bundle2.putString("button2", "click2");
mFirebaseAnalytics.logEvent("BusinessUserclick", bundle2);
break;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.