Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/basic-integration/rails/fizzy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@

/config/credentials/*.key
.DS_Store
.env
4 changes: 4 additions & 0 deletions apps/basic-integration/rails/fizzy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ gem "zip_kit"
gem "mittens"
gem "useragent", bc: "useragent"

# PostHog analytics and Rails instrumentation
gem "posthog-ruby", "~> 3.0"
gem "posthog-rails"

# Operations
gem "autotuner"
gem "mission_control-jobs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class Account::CancellationsController < ApplicationController

def create
Current.account.cancel

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "account_cancelled"
)

redirect_to session_menu_path(script_name: nil), notice: "Account deleted"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def show

def create
Current.account.exports.create!(user: Current.user).build_later

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "account_export_requested"
)

redirect_to account_settings_path, notice: "Export started. You'll receive an email when it's ready."
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def start_import(account)
import.process_later
end

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "account_import_started"
)

redirect_to account_import_path(import, script_name: account.slug)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ class ApplicationController < ActionController::Base
etag { "v1" }
stale_when_importmap_changes
allow_browser versions: :modern

private
def current_identity
Current.identity
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ class Boards::PublicationsController < ApplicationController

def create
@board.publish

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "board_published"
)
end

def destroy
@board.unpublish
@board.reload

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "board_unpublished"
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def new
def create
@board = Board.create! board_params.with_defaults(all_access: true)

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "board_created",
properties: { all_access: @board.all_access }
)

respond_to do |format|
format.html { redirect_to board_path(@board) }
format.json { head :created, location: board_path(@board, format: :json) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def index
def create
@comment = @card.comments.create!(comment_params)

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "comment_created"
)

respond_to do |format|
format.turbo_stream
format.json { head :created, location: card_comment_path(@card, @comment, format: :json) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ class Cards::PublishesController < ApplicationController
def create
@card.publish

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "card_published",
properties: { add_another: add_another_param? }
)

if add_another_param?
card = @board.cards.create!(status: :drafted)
redirect_to card_draft_path(card), notice: "Card added"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ def create
respond_to do |format|
format.html do
card = Current.user.draft_new_card_in(@board)

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "card_draft_started"
)

redirect_to card_draft_path(card)
end

format.json do
card = @board.cards.create! card_params.merge(creator: Current.user, status: "published")

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "card_created",
properties: { creation_method: "api" }
)

head :created, location: card_path(card, format: :json)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ def create
access_token = my_access_tokens.create!(access_token_params)
expiring_id = verifier.generate access_token.id, expires_in: 10.seconds

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "access_token_created",
properties: { permission: access_token.permission }
)

redirect_to my_access_token_path(expiring_id)
end

def destroy
my_access_tokens.find(params[:id]).destroy!

PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "access_token_revoked"
)

redirect_to my_access_tokens_path
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def sign_in(magic_link)
clear_pending_authentication_token
start_new_session_for magic_link.identity

PostHog.identify(
distinct_id: magic_link.identity.posthog_distinct_id,
properties: magic_link.identity.posthog_properties
)

PostHog.capture(
distinct_id: magic_link.identity.posthog_distinct_id,
event: "magic_link_signed_in",
properties: { requires_signup_completion: requires_signup_completion?(magic_link) }
)

respond_to do |format|
format.html { redirect_to after_sign_in_url(magic_link) }
format.json { render json: { session_token: session_token, requires_signup_completion: requires_signup_completion?(magic_link) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def signup_params
end

def welcome_to_account
PostHog.capture(
distinct_id: Current.identity.posthog_distinct_id,
event: "signup_completed"
)

respond_to do |format|
format.html do
flash[:welcome_letter] = true
Expand Down
8 changes: 8 additions & 0 deletions apps/basic-integration/rails/fizzy/app/models/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def send_magic_link(**attributes)
end
end

def posthog_distinct_id
id.to_s
end

def posthog_properties
{ email: email_address }
end

private
def deactivate_users
users.find_each(&:deactivate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "posthog"

api_key = ENV.fetch("POSTHOG_PROJECT_TOKEN", nil)
host = ENV.fetch("POSTHOG_HOST", nil)

if Rails.env.development?
if api_key.blank?
raise "POSTHOG_PROJECT_TOKEN variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once POSTHOG_PROJECT_TOKEN is configured"
end
if host.blank?
raise "POSTHOG_HOST variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once POSTHOG_HOST is configured"
end
end

if api_key.present? && host.present?
PostHog.init do |config|
config.api_key = api_key
config.host = host
end

PostHog::Rails.configure do |config|
config.auto_capture_exceptions = true
config.report_rescued_exceptions = true
config.auto_instrument_active_job = true
config.capture_user_context = true
config.current_user_method = :current_identity
config.user_id_method = :posthog_distinct_id
end
end
Loading