-
How to monitor social media interactions with Google Analytics 4
“Hey there,
So I was using Universal Analytics (it has since been deprecated). There, I had my way around tracking share events. Here’s the code of how I was doing it:
`js
gtag(‘event’, ‘facebook’, {
‘event_category’: ‘share’,
‘event_label’: ‘abc123’,
});
`
Then, to get the share data count, I queried like this:
`php
// endpoint: https://analyticsreporting.googleapis.com/v4/reports:batchGet
…
‘metrics’ => [
[‘expression’ => ‘ga:totalEvents’]
],
‘dimensions’ => [
[‘name’ => ‘ga:eventLabel’],
[‘name’ => ‘ga:eventAction’],
],
`
Alright, but now, we have Firebase Analytics, powered by Google Analytics 4. So, they give some recommendation [here](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#SHARE), and a mirror of it can be found [here](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#share) with this example:
`js
gtag(“event”, “share”, {
method: “Twitter”,
content_type: “image”,
item_id: “abc123”,
});
`
For querying this data, there’s a new API [here](https://developers.google.com/analytics/devguides/reporting/data/v1). They’ve also listed dimensions and metrics [here](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema). These include
eventName
,itemId
,method
,contentType
,eventValue
, andeventCount
.Here’s my issue – I can’t figure out how to use this new API to generate a report where event count is broken down like this:
| Event Method | Item Id | Count |
|————–|———|——-|
| Twitter | abc123 | 6 |
| Twitter | xyz987 | 27 |
| Facebook | abc123 | 14 |The real trouble is that I can’t seem to get the event counts by
itemId
at all.Oh! A recent announcement [here](https://developers.google.com/analytics/devguides/reporting/data/v1/changelog#2022-09-13_schema_compatibility_changes_announcement) states “Item-scoped dimensions like
itemName
are becoming incompatible with event-scoped metrics likeeventCount
.” I think this might play a role in the problem.Any ideas? Thanks!”
Log in to reply.