-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a1cc31
commit 38869f1
Showing
10 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Analytics | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
after_action :track_action | ||
end | ||
|
||
private | ||
|
||
def track_action | ||
ahoy.track "#{controller_path}##{action_name}", request.path_parameters | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# == Schema Information | ||
# | ||
# Table name: ahoy_events | ||
# | ||
# id :bigint not null, primary key | ||
# visit_id :bigint | ||
# user_id :bigint | ||
# name :string | ||
# properties :jsonb | ||
# time :datetime | ||
# | ||
# Indexes | ||
# | ||
# index_ahoy_events_on_name_and_time (name,time) | ||
# index_ahoy_events_on_properties (properties) USING gin | ||
# index_ahoy_events_on_user_id (user_id) | ||
# index_ahoy_events_on_visit_id (visit_id) | ||
# | ||
class Ahoy::Event < ApplicationRecord | ||
include Ahoy::QueryMethods | ||
|
||
self.table_name = "ahoy_events" | ||
|
||
belongs_to :visit | ||
belongs_to :user, optional: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# == Schema Information | ||
# | ||
# Table name: ahoy_visits | ||
# | ||
# id :bigint not null, primary key | ||
# visit_token :string | ||
# visitor_token :string | ||
# user_id :bigint | ||
# ip :string | ||
# user_agent :text | ||
# referrer :text | ||
# referring_domain :string | ||
# landing_page :text | ||
# browser :string | ||
# os :string | ||
# device_type :string | ||
# country :string | ||
# region :string | ||
# city :string | ||
# latitude :float | ||
# longitude :float | ||
# utm_source :string | ||
# utm_medium :string | ||
# utm_term :string | ||
# utm_content :string | ||
# utm_campaign :string | ||
# app_version :string | ||
# os_version :string | ||
# platform :string | ||
# started_at :datetime | ||
# | ||
# Indexes | ||
# | ||
# index_ahoy_visits_on_user_id (user_id) | ||
# index_ahoy_visits_on_visit_token (visit_token) UNIQUE | ||
# index_ahoy_visits_on_visitor_token_and_started_at (visitor_token,started_at) | ||
# | ||
class Ahoy::Visit < ApplicationRecord | ||
self.table_name = "ahoy_visits" | ||
|
||
has_many :events, class_name: "Ahoy::Event" | ||
belongs_to :user, optional: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Ahoy::Store < Ahoy::DatabaseStore | ||
def authenticate(data) | ||
# disables automatic linking of visits and users for GDPR compliance | ||
end | ||
end | ||
|
||
# remove cookie tracking and mask ips for GDPR compliance | ||
Ahoy.mask_ips = true | ||
Ahoy.cookies = :none | ||
|
||
# set to true for JavaScript tracking | ||
Ahoy.api = false | ||
|
||
# set to true for geocoding (and add the geocoder gem to your Gemfile) | ||
# we recommend configuring local geocoding as well | ||
# see https://github.com/ankane/ahoy#geocoding | ||
Ahoy.geocode = false |
62 changes: 62 additions & 0 deletions
62
db/migrate/20240403065507_create_ahoy_visits_and_events.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :ahoy_visits do |t| | ||
t.string :visit_token | ||
t.string :visitor_token | ||
|
||
# the rest are recommended but optional | ||
# simply remove any you don't want | ||
|
||
# user | ||
t.references :user | ||
|
||
# standard | ||
t.string :ip | ||
t.text :user_agent | ||
t.text :referrer | ||
t.string :referring_domain | ||
t.text :landing_page | ||
|
||
# technology | ||
t.string :browser | ||
t.string :os | ||
t.string :device_type | ||
|
||
# location | ||
t.string :country | ||
t.string :region | ||
t.string :city | ||
t.float :latitude | ||
t.float :longitude | ||
|
||
# utm parameters | ||
t.string :utm_source | ||
t.string :utm_medium | ||
t.string :utm_term | ||
t.string :utm_content | ||
t.string :utm_campaign | ||
|
||
# native apps | ||
t.string :app_version | ||
t.string :os_version | ||
t.string :platform | ||
|
||
t.datetime :started_at | ||
end | ||
|
||
add_index :ahoy_visits, :visit_token, unique: true | ||
add_index :ahoy_visits, [ :visitor_token, :started_at ] | ||
|
||
create_table :ahoy_events do |t| | ||
t.references :visit | ||
t.references :user | ||
|
||
t.string :name | ||
t.jsonb :properties | ||
t.datetime :time | ||
end | ||
|
||
add_index :ahoy_events, [ :name, :time ] | ||
add_index :ahoy_events, :properties, using: :gin, opclass: :jsonb_path_ops | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters