How can I filter Firebase events based on parameters?

Viewed 2501

In my iOS app I'm sending events to Firebase like this:

Analytics.logEvent(event, parameters: [
  AnalyticsParameterItemID: id,
  AnalyticsParameterItemName: name,
  AnalyticsParameterContentType: type,
])

For instance I can send the event complete_review with the id 12 representing the screen. This seems to work well and I see event data in my Firebase / Google Analytics dashboard.

However, I can't figure out how to filter based on these parameters, like id, name or type.

e.g. : To illustrate, I currently have: "There are 2000 completed reviews" ... but I really want "there are 500 completed reviews of id 1, 100 of id 2, 300 of id 3 ...".


I'm seeing from the documentation that I should find a "Edit parameter reporting" link, but it doesn't seem to appear for me and I just see a "mark as NPA" button:

enter image description here

Right now it seems like the only solution is to use the event name. This means that instead of complete_review with id set to 12, I would send complete_review_id_12 and just have tons of different events, export it and then re-parse it with a custom script... this feels pretty terrible, so I'm wondering if anyone had a better idea.

2 Answers

Okay in firebase you can mark up to 30 events as conversions, but that's it. If you're wanting to see specific data related to each event, per ID, you're going to have to get into BigQuery. BigQuery can seem daunting at first, but it's just like any other database with some sweet features, namely unnest() which is what you can use to filter events based on ID.

Firebase, by default, exports its data to BigQuery every 24 hours so your data is there and now it's an issue of getting that data parsed the way you're expecting. Fortunately you can export this data as JSON, XML, or as a table so you can use it however you want to, including in-app. Here's an example I used to parse and count events by ID in BigQuery.

You can access BigQuery by visiting the link https://console.cloud.google.com/bigquery?project= you may need to select your project at the top left hand side.

#standardSQL
SELECT DISTINCT
  // UNNEST() allows you to get a specific value from your nested
  // parameters. In this case I'm getting value.int_value and value.string_value.
  (SELECT value.int_value FROM UNNEST(event_params)
    WHERE key = 'some_ID') AS ID,
  (SELECT value.string_value FROM UNNEST(event_params)
    WHERE key = 'some_title') AS Title, 
  COUNT(1) Count
  
// INFO: If you build a query your last line will have the date as
// .events_20201015 and it will only query for that day. Replace the 
// 20201015 with a " * " to filter on ALL events.
FROM `your_table_name.analytics_243434300.events_*` t

WHERE 
  event_name = 'your_event_name'
GROUP BY ID, Title

This will return a table or JSON, depending on your preference, that has a count of each unique eventID with the data you want to identify that event. If you decide to go the dashboard route, and apply conversions, it will take 24 hours to update so don't expect results immediately.

Firebase is tracking screens automatically unless you set FirebaseScreenReportingEnabled to false in your Info.plist.

To get the maximum detail in reports, log the suggested events that make sense for your app and their prescribed parameters. This also ensures that you benefit from the latest Google Analytics features as they become available.

You can find a full list of those events here.

So you should use this code for screen tracking with custom value:

Analytics.logEvent(AnalyticsEventScreenView,
        parameters: [AnalyticsParameterScreenName: "ScreenName",
                     AnalyticsParameterScreenClass: "ScreenViewController",
                     "custom_value":customValue])

Filtering for the custom value works great in my dashboard.

For logging custom events, you should use:

Analytics.logEvent("custom_event", parameters: ["custom_value":customValue])
Related