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

feat(experiments): Tag support for shared metrics #28061

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

danielbachhuber
Copy link
Contributor

@danielbachhuber danielbachhuber commented Jan 29, 2025

From https://posthog.slack.com/archives/C07PXH2GTGV/p1738179059221599

  1. the ability to create metric groups that you can add to experiments.

Changes

One or more tags can be added to a shared metric:

CleanShot 2025-01-29 at 13 16 21

The tags are listed in the shared metrics table:

CleanShot 2025-01-29 at 13 36 38@2x

When your shared metrics have some tags, you can click on the tag to quickly select all matching metrics:

CleanShot 2025-01-30 at 05 36 17

How did you test this code?

Manual review.

@danielbachhuber danielbachhuber requested review from raquelmsmith and a team January 29, 2025 21:19
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds tag support for shared metrics in experiments, allowing users to organize and quickly filter metrics using tags in the UI.

Key changes:

  • Added experiment_saved_metric foreign key to TaggedItem model with corresponding database constraints and migrations
  • Integrated TaggedItemSerializerMixin into ExperimentSavedMetricSerializer to handle tag operations
  • Added tag UI components in SharedMetric.tsx for managing tags on individual metrics
  • Implemented quick-select functionality in SharedMetricModal.tsx to filter metrics by clicking tags
  • Added conditional tag column in shared metrics table based on TAGGING feature flag

The implementation follows existing patterns for tag management in PostHog and includes proper database constraints to maintain data integrity.

8 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 74 to 81
const availableTags = Array.from(
new Set(
availableSharedMetrics
.filter((metric: SharedMetric) => metric.tags)
.flatMap((metric: SharedMetric) => metric.tags)
.filter(Boolean)
)
).sort()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider memoizing availableTags with useMemo to prevent recalculation on every render

tags: newTags,
})
}}
saving={false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: saving prop is hardcoded to false - should reflect actual saving state from sharedMetricLogic to show proper loading state

Copy link
Contributor

github-actions bot commented Jan 29, 2025

Size Change: +756 B (+0.06%)

Total Size: 1.16 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.16 MB +756 B (+0.06%)

compressed-size-action

@raquelmsmith
Copy link
Member

raquelmsmith commented Jan 29, 2025

Nice love the speed on this! TY ❤️

I think there's opportunity for better UX for this, as this feels kinda "slapped on."

An example I thought of was Google Drive's folder thing to move a document - but instead of moving you are selecting the tag (which shouldn't be so obviously a tag, maybe?)

image

So...

  1. Click Add primary/secondary metric
  2. Select "shared metric"
  3. See just a list of collections (folders in the Google Drive example)
  4. Select the collection (which is a tag in the db but called "collection" or something here)
  5. Can either just "select all" or "select some" - if "select some" they can then see all the individual metrics and manually uncheck whatever they don't want
  6. What if they want to now add another metric that wasn't in that collection? Maybe they just go through the flow again for now, but it'd be nice to be able to create a new one on the fly eventually, or select another one from a different list.

Thoughts?

@danielbachhuber
Copy link
Contributor Author

An example I thought of was Google Drive's folder thing to move a document - but instead of moving you are selecting the tag (which shouldn't be so obviously a tag, maybe?)

[...]

Thoughts?

Could, not strongly against. However, Google Docs doesn't let you select some docs from folder A and some docs from folder B:

CleanShot.2025-01-29.at.13.44.06.mp4

If we implemented such an ability, it would be difficult to see what's selected in folder A when you're in folder B. We could then add some UI that shows the selected metrics, but I think that's veering into overly complex territory.

I think there's opportunity for better UX for this, as this feels kinda "slapped on."

To help me better understand your perspective, what makes you feel like it's "slapped on"? Are there small things we could do to make it feel more polished?

To help inform the decision: there's currently one team with 28 metrics. Everyone else has 10 or less.

SELECT team_id, COUNT(*) AS row_count
FROM postgres_posthog_experimentsavedmetric
GROUP BY team_id ORDER BY row_count DESC

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@raquelmsmith
Copy link
Member

Yeah I think selecting metrics from a single collection for now is fine. If they want metrics from another collection they just go through the flow again.

what makes you feel like it's "slapped on"?

I think it's that in my mental model a "tag" is just metadata on the thing - it's a lower or secondary level of importance.

Whereas with a folder structure, you're making a primary decision about where something belongs and what it means.

I think it's good that we use our server implementation of tags for this, as it's existing and allows us to assign metrics to multiple "collections." But the folder mental model is better for this IMO.

Are there small things we could do to make it feel more polished?

I think it could be as simple as renaming "tag" to "collection", giving the names more space (tags feel like they should just be a single word, but I assume a collection will be multiple words).

Like if you were designing this from scratch, how would you do it? Probably more of the folder structure like google drive. And then we say "what existing tech do we have to make this work?"


These are all just my opinions, and getting something out soon is better than fussing about the ideal solution forever 😄 So feel free to move forward with what you think is best here!

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@danielbachhuber danielbachhuber force-pushed the experiments/tagged-shared-metrics branch from 487e8c9 to 889f548 Compare January 30, 2025 01:35
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@jurajmajerik
Copy link
Contributor

I'm quite happy with how this works, with the caveat that we should call it Collections, as Raquel suggested. Another thing to consider is that tagging is a Teams/Enterprise feature, which means it will trigger a paywall if you don’t have access to it. That seems fine to me, as I’d expect larger customers to need this - just wanted to surface it here.

@danielbachhuber
Copy link
Contributor Author

with the caveat that we should call it Collections, as Raquel suggested.

Tell me more? How is this "Collections" concept different than tags?

Another thing to consider is that tagging is a Teams/Enterprise feature, which means it will trigger a paywall if you don’t have access to it. That seems fine to me, as I’d expect larger customers to need this - just wanted to surface it here.

Yep, this is consistent with dashboards, feature flags, actions, insights, event definitions, and property definitions.

Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell me more? How is this "Collections" concept different than tags?

I was thinking of renaming it in the UI to make it clearer that this is for grouping metrics into collections. But I realize that would make it inconsistent with the rest of the app, where tags are used.

Good to go as is 👍

@@ -0,0 +1,92 @@
# Generated by Django 4.2.18 on 2025-01-30 17:45
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

4 participants