-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
16 changed files
with
283 additions
and
28 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,34 @@ | ||
ahoy.configure({ | ||
trackVisits: false // Disable automatic client-side visit tracking | ||
}); | ||
|
||
var Tracking = { | ||
init: function () { | ||
$('[data-trackable]').click(Tracking.track); | ||
}, | ||
|
||
/** | ||
* Function that registers a click on an outbound link in Analytics. | ||
* This function takes a valid URL string as an argument, and uses that URL string | ||
* as the event label. Setting the transport method to 'beacon' lets the hit be sent | ||
* using 'navigator.sendBeacon' in browser that support it. | ||
*/ | ||
track: function () { | ||
if (this.dataset.trackableType && this.dataset.trackableId) { | ||
ahoy.track('Visited Link', { | ||
url: this.href, | ||
trackable_type: this.dataset.trackableType, | ||
trackable_id: parseInt(this.dataset.trackableId) | ||
}); | ||
} | ||
if (window.gtag) { | ||
gtag('event', 'click', { | ||
'event_category': 'outbound', | ||
'event_label': url, | ||
'transport_type': 'beacon', | ||
'event_callback': function() {} // Not needed | ||
}); | ||
} | ||
return true; | ||
} | ||
} |
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,8 @@ | ||
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,6 @@ | ||
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
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,17 @@ | ||
class Ahoy::Store < Ahoy::DatabaseStore | ||
end | ||
|
||
# set to true for JavaScript tracking | ||
Ahoy.api = true | ||
|
||
# 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 | ||
|
||
# GDPR compliance | ||
Ahoy.mask_ips = true | ||
Ahoy.cookies = false | ||
|
||
# Disable automatic server-side visit tracking | ||
Ahoy.server_side_visits = :when_needed |
61 changes: 61 additions & 0 deletions
61
db/migrate/20230617092354_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,61 @@ | ||
class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[6.1] | ||
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 | ||
|
||
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
Oops, something went wrong.