Skip to content

Assign running experiment to logged_in_user #711

Open
@puneetpandey

Description

@puneetpandey

Hi,

I need help with below use-case:

  1. A/B test with 3 add to cart buttons
  2. A user / visitor (doesn't require login) can add items to their cart
  3. They need to be logged-in/signup for checkout (checkout requires current_user object)

My Setup:

# A/B test: Split gem setting starts here
cookie_adapter = Split::Persistence::CookieAdapter
redis_adapter = Split::Persistence::RedisAdapter.with_config(
  lookup_by: -> (context) { context.send(:current_user).try(:id) },
  expire_seconds: 2592000
)

Split.configure do |config|
  config.redis = 'redis://localhost:6379'
  config.persistence = Split::Persistence::DualAdapter.with_config(
    logged_in: -> (context) { !context.send(:current_user).try(:id).nil? },
    logged_in_adapter: redis_adapter,
    logged_out_adapter: cookie_adapter
  )
  config.persistence_cookie_length = 7.days.to_i
  config.experiments = {
    plan_pricing_container: {
      alternatives: [
        {
          name: "original",
          percent: 50,
          metadata: {
            "original": {"text": "The original plan pricing container"}
          }
        },
        {
          name: "buy_this_plan",
          percent: 25,
          metadata: {
            "buy_this_plan": {"text": "Button with text Buy this plan"}
          }
        },
        {
          name: "purchase_options",
          percent: 25,
          metadata: {
            "purchase_options": {"text": "Button with text Purchase options"}
          }
        }
      ],
      goals: ["add_to_cart", "purchase"]
    }
  }
  config.allow_multiple_experiments = true
end
# A/B test: Split gem setting ends here

The way I am calling conversions for the goals:

  1. On Cart Page: ab_finished({plan_pricing_container: "add_to_cart"}, reset: false)
  2. On Checkout: ab_finished(plan_pricing_container: "purchase", reset: false)

Use-case:

  1. Guest sees "buy_this_plan" button > Experiment starts
  2. Guest adds item to cart > Experiment successfully completed for add_to_cart goal
  3. Guest logs-in now and completed the checkout

Expected behaviour
I should see "completed" for both add_to_cart and purchase goals.

Actual behaviour
I see this (nothing happens):
image

It seems there few issues:

  1. I am unable to assign a running experiment to a logged_in_user (if they don't change the browser).
  2. Using both cookie_adapter and redis_adapter not working. I end up seeing conversion not getting tracked for purchase goal (screenshot above).
  3. If I remove cookie_adapter and redis_adapter blocks and repeat the same steps then after checkout I see -ve events (see below). (Note: add_to_cart worked fine but purchase resulted in this)
Screenshot 2023-07-17 at 1 11 54 PM

The traffic on my website is on the higher side, so I found and decided to go for CookieAdapter and use Redis Adapter only for logged_in_user/s.

Please suggest!

% bundle info split
  * split (4.0.2)
	Summary: Rack based split testing framework
	Homepage: https://github.com/splitrb/split
	Source Code: https://github.com/splitrb/split
	Wiki: https://github.com/splitrb/split/wiki
	Changelog: https://github.com/splitrb/split/blob/main/CHANGELOG.md
	Bug Tracker: https://github.com/splitrb/split/issues
	Mailing List: https://groups.google.com/d/forum/split-ruby
	Path: /.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/split-4.0.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions