Commit 2a553a98 authored by James Lopez's avatar James Lopez

Merge branch 'jj-respect-tracking-better' into 'master'

Stop pushing experiment data to the client (using Gon) when we shouldn't

See merge request gitlab-org/gitlab!56405
parents 293b4964 9b13634f
...@@ -10,9 +10,10 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp ...@@ -10,9 +10,10 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
end end
def publish(_result = nil) def publish(_result = nil)
return unless should_track? # don't track events for excluded contexts
track(:assignment) # track that we've assigned a variant for this context track(:assignment) # track that we've assigned a variant for this context
# push the experiment data to the client
begin begin
Gon.push({ experiment: { name => signature } }, true) # push the experiment data to the client Gon.push({ experiment: { name => signature } }, true) # push the experiment data to the client
rescue NoMethodError rescue NoMethodError
......
...@@ -58,6 +58,15 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -58,6 +58,15 @@ RSpec.describe ApplicationExperiment, :experiment do
end end
describe "publishing results" do describe "publishing results" do
it "doesn't track or push data to the client if we shouldn't track", :snowplow do
allow(subject).to receive(:should_track?).and_return(false)
expect(Gon).not_to receive(:push)
subject.publish(:action)
expect_no_snowplow_event
end
it "tracks the assignment" do it "tracks the assignment" do
expect(subject).to receive(:track).with(:assignment) expect(subject).to receive(:track).with(:assignment)
......
...@@ -6,6 +6,7 @@ require_relative 'stub_snowplow' ...@@ -6,6 +6,7 @@ require_relative 'stub_snowplow'
# This is a temporary fix until we have a larger discussion around the # This is a temporary fix until we have a larger discussion around the
# challenges raised in https://gitlab.com/gitlab-org/gitlab/-/issues/300104 # challenges raised in https://gitlab.com/gitlab-org/gitlab/-/issues/300104
require Rails.root.join('app', 'experiments', 'application_experiment')
class ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass class ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass
def initialize(...) def initialize(...)
super(...) super(...)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment