-->

Google Analytics screenname for events

2019-07-01 17:59发布

问题:

I'm confused about the "Screen Name" dimension in Google Analytics.

If you go to Behaviour -> Events -> Screens you'll see it.

I'm wondering how you can attach a screen name to an event. Currently I'm tracking screenview (hits) and event (hits). I thought analytics could get the screenname for an event by looking at the last screenview. But this doesn't seem to be the case.

Btw I'm using the Measurement Protocol.

Any ideas on this?

回答1:

I thought analytics could get the screenname for an event by looking at the last screenview. But this doesn't seem to be the case.

No, this is not the case. All data you send to Google Analytics is scoped to either a User, a Session, or a Hit (where every hit belongs to a session, and every session belongs to a user).

For user level data (e.g. client ID), Google Analytics is able to apply that data to all session and all hits for that users, but in the case of screen name and event data (e.g. event category and event action), these are all scoped to the hit level and therefore only apply to the hit they are sent with.

Most of the tracking libraries (including analytics.js and the Android and iOS SDKs) have the concept of a tracker, which is an object that can store data and send data to Google Analytics via the Measurement Protocol.

If you want to associate a particular screen name with all events that occurred when the user was on that particular screen, you'd need to send that screen name with all event hits as well. For convenience, the tracker objects allow you to set data on them, and then that data will get sent with all subsequent hits, so in your case you'd want to set the screen name on the tracker before sending any event hits.

Here's an example implementation using analytics.js:

ga('create', 'UA-XXXXX-Y', 'auto');

// Sets the `screenName` field to "Home Screen" for this
// and all subsequent hits.
ga('set', 'screenName', 'Home Screen');

// Sends a screenview hit for "Home Screen"
ga('send', 'screenview');

// Sends an event hit. Since the `screenName` field was
// already set on the tracker, that data will get sent
// with this hit as well.
ga('send', 'event', 'Navigation Links', 'click', '/about');

Note: all links are to analytics.js documentation pages, but the concepts apply to the Android and iOS SDKs as well.



回答2:

You can not attach screen name to an event. Instead all events that happen after you send screen view are attributed to the screen unless your session times out.

To achieve the same using the measurement protocol, send screenview measurement first followed by your event measurement. You might need to add all required params to both measurement for this to work.