How to display the Vanity Dashboard in another server?

114 Views Asked by At

I am using Vanity in Server A. But for the dashboard, I want to display it on Server B.

Steps Done:

  1. Added gem 'vanity' in the Gemfile
  2. Added vanity.yml (used same database as Server A)
  3. Added vanity controller

But all I see now when I go to localhost:3000/vanity is a page with only 'Generated by Vanity' in it.

Do I need to add in the experiments files as well? But as much as possible I don't want to copy them over to Server B as it's already in Server A. I just need the Dashboard to be displayed in Server B.

enter image description here

1

There are 1 best solutions below

0
On

Vanity does use the experiment files as the source of truth for things like alternative values, so copying those files would be the most straightforward approach. (Maybe a git submodule could help to keep them in one spot?)

If something a bit hacky is okay, this might work in the read-only app:

# config/initializers/vanity.rb
::Rails.configuration.after_initialize do
  Vanity::Adapters::ActiveRecordAdapter::VanityExperiment.all.each do |experiment|
    id = experiment.experiment_id
    experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, id.humanize)
    experiment.default(Vanity::Adapters::ActiveRecordAdapter::VanityParticipant.where(experiment_id: id).first.seen)
    used_alternatives = Vanity::Adapters::ActiveRecordAdapter::VanityParticipant.where(experiment_id: id).pluck(:seen).uniq
    if used_alternatives.size >= 2
      # If we have at least 2 alternatives, set them, otherwise use the default true/false
      experiment.alternatives(*used_alternatives)
    end
    Vanity.playground.experiments[id] = experiment
  end
end

This pulls the available info from the database (so doesn't have the alternatives names, it just has the index numbers of the alternatives in the experiment file), and makes some assumptions, but seems to load the data.