New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto metric support for GA4 & BigQuery #1423
Conversation
Your preview environment pr-1423-bttf has been deployed. Preview environment endpoints are available at: |
…he existing auto metric integrations. Will need to come back and find an abstraction so both work.
…k segment & rudderstack.
currentDateTime.valueOf() - 7 * 60 * 60 * 24 * 1000 | ||
); | ||
const startYear = sevenDaysAgo.getFullYear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very verbose - open to suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the date-fns
package available on the back-end. It should help accomplishing this easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bttf Great suggestion - thank you! I've pushed up changes utilizing date-fns
- way less verbose and way better readability. I also added a dateFormat
property to the SchemaFormatConfig
for added flexibility down the road.
Features and Changes
This PR adds auto metric support for Google Analytics 4. In order to support this, there were a few changes that were necessary within
SQLIntegration
due to the inherent differences between how Google Analytics 4 and the existing event trackers with auto metric support (Segment & Rudderstack) store tracked events.Segment & Rudderstack have a single table that outlines all of the unique events that are tracked, and then each row of that tables gets it's own table where each instance of that event are recorded.
Google Analytics 4, however, stores all tracked events on a single table (kinda, they're stored on intraday tables, but all share the same schema).
In order to make auto metrics work with both approaches, we had to introduce an
eventHasUniqueTable
param withinSchemaFormatConfig
and we also had to introduce agroupByColumns
param within the same config.These two params ultimately power how we're able to support both approaches as the underlying queries are materially different, especially the actual metric queries. With Segment/Rudderstack, you could query the event's table directly (e.g. if the tracked event was "page_viewed" the FROM clause could be
FROM datasource.schema.page_viewed
), but with Google Analytics 4, all events live on the same table, so to build the metric, you need aWHERE
clause. (e.g.WHERE event_name in ('page_viewed')
).Testing
Other Notes
NewDataSourceForm
to allow orgs to opt-in to auto metrics when adding a new GA4 data source. If this PR has not been merged and you'd like to test this PR locally, you can do so by changingconst hasStep2 = true
withinNewDataSourceForm.tsx
. Otherwise, if the PR linked has been merged, you can create a GA4 data source and then use the "Discover Metrics" button. If you need a sample GA4 data source to test this with, please just reach out to me (@mknowlton89) via Slack.