How do you track screens as pages on Google Analytics? (website view using app data)

35
October 09, 2019, at 3:00 PM

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?

Answer 1

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;

            }
    }
READ ALSO
Notification not receive when Application terminated in android

Notification not receive when Application terminated in android

I use firebase push notification to device tokenWhen app is opening or in foreground I can get notification well

53
How do I connect an Azure MySQL Database to my iOS and Android App

How do I connect an Azure MySQL Database to my iOS and Android App

Entirely new to this and was hoping to find some reasonably straightforward API's or documentation to connect the MySQL database I have on Azure to the iOS and Android apps I have in development

22
why Dialog doesn't show in Kotlin?

why Dialog doesn't show in Kotlin?

I want to create a Dialog window when I click the Floating Action ButtonBut, when I click the button, just appears the Toast message

36
How to custom claims token to firebase firestore rules via Android App?

How to custom claims token to firebase firestore rules via Android App?

I'm trying to customize claims token to firestore rule via Cloud Functions but it do not appear a good solution because it throws an exception when I try create an user via Android Application like follow:

41