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

4032 migrate to ahoy #4044

Merged
merged 24 commits into from
Feb 21, 2022
Merged

4032 migrate to ahoy #4044

merged 24 commits into from
Feb 21, 2022

Conversation

entantoencuanto
Copy link
Member

@entantoencuanto entantoencuanto commented Feb 8, 2022

Closes #4032

✌️ What does this PR do?

  • Removes mixpanel and google analytics tracking code (except if analytics is configured on site)
  • Adds and configure ahoy to track each request creating an event by site. This includes adding a column to the events table and an association with Site model.
  • Adds sidekiq-bounce and defines a GobiertoCommon::EventCreatorJob to create ahoy events which is used from controller concern for each request
  • The event stores info of the request and its params filtering some. The ahoy config file also includes some GDPR compliance settings and:
    • Masks IPs on visits
    • Disables use of cookies by ahoy

🔍 How should this be manually tested?

👀 Screenshots

Before this PR

After this PR

:shipit: Does this PR changes any configuration file?

  • new environment variable in .env.example?
  • deleted entries in config/application.yml?
  • new entry in config/secrets.yml?

(Changes in these files might need to update the role in Ansible)

📖 Does this PR require updating the documentation?

Pending

@furilo
Copy link
Member

furilo commented Feb 8, 2022 via email

@ferblape
Copy link
Member

ferblape commented Feb 9, 2022

FYI, we still have rollbar because of the JS #3240. I'm going to move this issue to Business as usual

@entantoencuanto entantoencuanto marked this pull request as ready for review February 9, 2022 16:24
Copy link
Member

@ferblape ferblape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just two things:

  • should it be tested in some way
  • remember to add the ansible PR and update the documentation in regards to the modifications of the config/application.yml

@ferblape
Copy link
Member

ferblape commented Feb 17, 2022

Hmmm, this is not working well, if you check the latest events from ahoy_events table they are without visit_id nor site_id (I'm generating them visiting Getafe staging site). Please review that

-[ RECORD 1 ]---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------
id         | 605
visit_id   |
user_id    |
site_id    |
name       | gobierto_people/people#show
properties | {"slug": "rafael-garcia", "action": "show", "locale": "es", "method": "GET", "controller": "gobierto_people/people"}
time       | 2022-02-17 05:01:23.547261

@furilo
Copy link
Member

furilo commented Feb 17, 2022 via email

@entantoencuanto
Copy link
Member Author

I made a change to not use bounce, and by mistake it was not saving the site correctly for visits with not authenticated users, but the schema of events and method to name them (controller#action) are the same. The only difference is that instead of using an organization_id gobierto events use a site_id, I can change it.

After talking with Victor I am using a different way of associating visits and events that I think can also be useful in contratos: At the moment of enqueuing the job to create the event from the controller there is a current_visit available which is passed to the job

@ferblape
Copy link
Member

@entantoencuanto thanks, now ahoy_events are tracking the site_id properly.

Would it be possible to add the site_id also to the field ahoy_visits? If we want to give the metric unique visitors to a single site right now it's not possible (please confirm @furilo).

@furilo
Copy link
Member

furilo commented Feb 17, 2022 via email

@entantoencuanto
Copy link
Member Author

Yes, it's possible, but currently the same visit can use different site_ids. For example, currently if I change in staging of site from the same browser the visit remains the same. I can investigate if a different visit can be generated for each site

Or may I do the same as I did with the user_id field, I can update the site_id when it changes

@ferblape
Copy link
Member

If the same user visits two sites it should be tracked as two visits, because sites should be independent. Customers don't care if the application is multitenant or there are N applications.

@furilo
Copy link
Member

furilo commented Feb 17, 2022 via email

This works when Ahoy.cookies is set to false. If cookies are used
the methods to track with cookies should be ovewritten. This hack
work by using some classes inherited from Ahoy ones which includes
site by:

* Defining an Ahoy::GobiertoTracker inheriting from Ahoy::Tracker wich
  includes site in visit_anonimity_set and visitor_anonimity_set methods
  (used to detect if visit exists previously)
* Ovewriting visit and track_visit in Ahoy::Store class to include site
Copy link
Member

@ferblape ferblape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it works as expected!

@ferblape ferblape merged commit 901d97c into master Feb 21, 2022
@ferblape ferblape deleted the 4032-migrate_to_ahoy branch February 21, 2022 03:43
@ferblape ferblape restored the 4032-migrate_to_ahoy branch February 22, 2022 03:40
@ferblape
Copy link
Member

@entantoencuanto there's something I missed in the acceptance that is broken. Your PR doesn't work when a customer has a google analytics key setup (the first point of your PR description). See that you are removing the ga function, while it's necessary: https://rollbar.com/Populate/gobierto/items/6057/?utm_campaign=exp_repeat_item&utm_medium=email&utm_source=rollbar-notification&utm_content=control

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

Successfully merging this pull request may close these issues.

Migrate from Google Analytics and Mixpanel to Ahoy
3 participants