forked from houndci/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Base approach on http://robots.thoughtbot.com/segment-io-and-ruby. * Add `utm_` campaigns as properties on user creation so cohort analysis can be done on a per-campaign basis later on. * Use special Segment.io `revenue` property and special `campaign` context. https://segment.io/docs/tracking-api/track/ * Ignore Redis backup dump file. https://trello.com/c/gwFd8KCN
- Loading branch information
Dan Croak
committed
Aug 21, 2014
1 parent
b6daf1f
commit 7b3d921
Showing
20 changed files
with
283 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
# | ||
# If you find yourself ignoring temporary files generated by your text editor | ||
# or operating system, you probably want to add a global ignore instead: | ||
# git config --global core.excludesfile ~/.gitignore_global | ||
|
||
# Ignore bundler config | ||
.env | ||
/.bundle | ||
|
||
# Ignore the default SQLite database. | ||
/db/*.sqlite3 | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/*.log | ||
/tmp | ||
|
||
.env | ||
dump.rdb |
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
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,60 @@ | ||
class Analytics | ||
class_attribute :backend | ||
self.backend = AnalyticsRuby | ||
|
||
def initialize(user, params = {}) | ||
@user = user | ||
@params = params | ||
end | ||
|
||
def track_signed_up | ||
track(event: "Signed Up", context: { campaign: campaign_params }) | ||
end | ||
|
||
def track_signed_in | ||
track(event: "Signed In") | ||
end | ||
|
||
def track_activated(repo) | ||
track(event: "Activated Public Repo", properties: repo_properties(repo)) | ||
end | ||
|
||
def track_deactivated(repo) | ||
track(event: "Deactivated Public Repo", properties: repo_properties(repo)) | ||
end | ||
|
||
def track_reviewed(repo) | ||
track(event: "Reviewed Repo", properties: repo_properties(repo)) | ||
end | ||
|
||
def track_subscribed(repo) | ||
track(event: "Subscribed Private Repo", properties: repo_properties(repo)) | ||
end | ||
|
||
def track_unsubscribed(repo) | ||
track(event: "Unsubscribed Private Repo", properties: repo_properties(repo)) | ||
end | ||
|
||
private | ||
|
||
def track(options) | ||
backend.track({ | ||
active_repos_count: user.repos.active.count, | ||
user_id: user.id, | ||
}.merge(options)) | ||
end | ||
|
||
def campaign_params | ||
{ | ||
medium: params[:utm_medium], | ||
name: params[:utm_campaign], | ||
source: params[:utm_source], | ||
}.reject { |_, value| value.blank? } | ||
end | ||
|
||
def repo_properties(repo) | ||
{ name: repo.full_github_name, revenue: repo.price } | ||
end | ||
|
||
attr_reader :params, :user | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class FakeAnalyticsRuby | ||
def initialize | ||
@tracked_events = EventsList.new([]) | ||
end | ||
|
||
def track(options) | ||
@tracked_events << options | ||
end | ||
|
||
delegate :tracked_events_for, to: :tracked_events | ||
|
||
private | ||
|
||
attr_reader :tracked_events | ||
|
||
class EventsList | ||
def initialize(events) | ||
@events = events | ||
end | ||
|
||
def <<(event) | ||
@events << event | ||
end | ||
|
||
def tracked_events_for(user) | ||
self.class.new( | ||
events.select do |event| | ||
event[:user_id] == user.id | ||
end | ||
) | ||
end | ||
|
||
def named(event_name) | ||
self.class.new( | ||
events.select do |event| | ||
event[:event] == event_name | ||
end | ||
) | ||
end | ||
|
||
def has_keys?(options) | ||
events.any? do |event| | ||
(options.to_a - event.to_a).empty? | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :events | ||
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
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.