Skip to content
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

Merged
merged 13 commits into from Jul 14, 2023
Merged

Conversation

mknowlton89
Copy link
Collaborator

@mknowlton89 mknowlton89 commented Jul 3, 2023

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 within SchemaFormatConfig and we also had to introduce a groupByColumns 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 a WHERE clause. (e.g. WHERE event_name in ('page_viewed')).

Testing

  • Create a new GA4 data source and ensure you can create auto metrics correctly
  • Create a new Segment data source and ensure you can create auto metrics correctly without any regressions

Other Notes

  • If this PR goes out first, I will update the docs in this PR to update the list of event trackers that support auto metrics.
  • Additionally, we've made the decision that moving forward, creating auto metrics will be done via the Metrics page, or the datasource/id page via the "Discover Metrics" button. As such, this PR doesn't include any updates to the 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 changing const hasStep2 = true within NewDataSourceForm.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.

@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Your preview environment pr-1423-bttf has been deployed.

Preview environment endpoints are available at:

@mknowlton89 mknowlton89 self-assigned this Jul 11, 2023
currentDateTime.valueOf() - 7 * 60 * 60 * 24 * 1000
);
const startYear = sevenDaysAgo.getFullYear();
Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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.

@mknowlton89 mknowlton89 marked this pull request as ready for review July 11, 2023 19:53
@mknowlton89 mknowlton89 requested review from jdorn and a team July 11, 2023 19:54
@mknowlton89 mknowlton89 requested a review from bttf July 12, 2023 15:03
@mknowlton89 mknowlton89 merged commit 4d5f545 into main Jul 14, 2023
3 checks passed
@mknowlton89 mknowlton89 deleted the mk/ga4-auto-metrics branch July 14, 2023 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants