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

Participants stop showing up on dashboard when I run the field_test_events migration #3

Closed
kyleschmolze opened this issue May 17, 2017 · 5 comments

Comments

@kyleschmolze
Copy link
Contributor

If I run rails g field_test:events and run the migration, then add some goals and track conversions with them, the dashboard stops reporting any new participants. All numbers show up as 0, even though I can see that the FieldTest::Memberships are being created. Once I rollback the migration, the dashboard shows the proper numbers again. Don't have time to try to debug this right now, but I can later, especially if you have any ideas where to look!

BTW thanks for this great gem!

@ankane
Copy link
Owner

ankane commented Jun 13, 2017

Hey @kyleschmolze, different code paths are run after the field_test_events table is created. Here's a good place to start debugging:

def use_events?

@pedrorio
Copy link

@kyleschmolze , did you have any progress on this? I am having the same issue.

@kyleschmolze
Copy link
Contributor Author

Yeah, I haven't had time to finish, yet, but I have some code along the right path. The problem is with the way the "participated" number is calculated here. The memberships-events join prevents any memberships from being returned that don't also have an event. And since events are only recorded for converted users, this means "participated" will always be equal to "converted" in this calculation, and so it will say 100% conversion rate, and ignore all un-converted users (returning 0 for that).

Instead, I just split it into 2 queries. One to calculate the number of total participants, and one to get the number of converted participants (using the same join). My code looks like this, starting on line 99:

relation = memberships
relation = relation.where("created_at >= ?", started_at) if started_at
relation = relation.where("created_at <= ?", ended_at) if ended_at

if use_events?
  participants = relation.group(:variant).count

  data = {}
  data = relation.joins(:events).where(field_test_events: {name: goal}).uniq.group_by(&:variant)
  data.keys.each do |variant|
    data[[variant, true]] = data[variant].length
    data[[variant, false]] = participants[variant].to_i - data[variant].length
    data.delete variant
  end

  # if no conversions, make sure to still put the participants
  participants.keys.each do |variant|
    if data[[variant, true]].blank?
      data[[variant, true]] = 0
      data[[variant, false]] = participants[variant].to_i
    end
  end
else
  data = relation.group(:variation, :converted).count
end

@pedrorio
Copy link

I also had this behaviour on my project.
I am trying to implement a recommendation system but will come back to take a look at this.

@pedrorio
Copy link

PS: @ankane Thanks for your awesome gems

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

No branches or pull requests

3 participants