Verified Solution[gitlab-org/gitlab] Track usage of the Rapid Diffs opt-in toggle
Sponsored Content
### ROOT CAUSE
The issue involves tracking user opt-in behavior for the Rapid Diffs feature in GitLab merge requests (MRs). Currently, there is no analytics event triggered when a user enables the toggle. The root cause is the absence of tracking code to record this user interaction, making it impossible to measure adoption or usage of the feature.
### CODE FIX
To track the opt-in event, we need to:
1. Add an analytics event when the user enables the toggle.
2. Use GitLab's `Tracking` module to record the event with appropriate properties.
Here's the fix:
```ruby
# app/controllers/projects/merge_requests/rapid_diffs_controller.rb
class Projects::MergeRequests::RapidDiffsController < ApplicationController
before_action :authenticate_user!
def update
@project = Project.find(params[:project_id])
@merge_request = MergeRequest.find(params[:merge_request_id])
@enabled = params[:rapid_diffs][:enabled] == 'true'
# Update the feature flag for the project (or user, depending on scope)
Spree::FeatureFlag::RapidDiffs::FeatureToggleService.call(@project, @enabled)
# Track the opt-in event
if @enabled
Gitlab::Tracking::Analytics.track(
'rapid_diffs_opt_in',
current_user.id,
project_id: @project.id,
merge_request_id: @merge_request.id
)
end
head :ok
end
end
```
This code:
- Updates the feature flag for the project (or user, adjust as needed).
- Triggers an analytics event (`rapid_diffs_opt_in`) when the toggle is enabled.
- Includes properties like `user_id`, `project_id`, and `merge_request_id` for context.
The event should be defined in GitLab's analytics infrastructure (e.g., in `app/lib/analytics/events/`) to ensure proper data collection.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[golang/go] x/perf/cmd/benchstat: OOM-kill
[golang/go] x/vuln: fails just released go1.25.8 with 2 CVEs
[StackOverflow/rust] Embed document in PDF with Rust pdf-writer crate