From d410e67b590e795e8d1eb244cc21c3d734eee869 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 15:37:12 -0600 Subject: [PATCH 01/28] identify users on key pages --- app/views/newflow/base/profile_newflow.html.erb | 9 +++++++-- .../newflow/signup/_signup_done_template.html.erb | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index faf6382b0b..49dcb74e67 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -5,6 +5,13 @@ <% content_for :head do %> <%= javascript_include_tag "profile" %> + <% end %>
@@ -203,7 +210,5 @@ OX.Profile.Name.editable($('#name'), { last_name: "<%= current_user.last_name %>", suffix: "<%= current_user.suffix %>" }); - - <% end # javscript content block %> diff --git a/app/views/newflow/signup/_signup_done_template.html.erb b/app/views/newflow/signup/_signup_done_template.html.erb index 0b88788464..0ff6413213 100644 --- a/app/views/newflow/signup/_signup_done_template.html.erb +++ b/app/views/newflow/signup/_signup_done_template.html.erb @@ -29,3 +29,13 @@ <% end %>
+ +<%= content_for :page_specific do %> + +<% end %> \ No newline at end of file From 1b336f94736c0885b6628193c3f81ec6a4a9494e Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 17:26:43 -0600 Subject: [PATCH 02/28] refactor --- app/controllers/application_controller.rb | 18 +++++++++- .../external_user_credentials_controller.rb | 4 +-- .../newflow/educator_signup_controller.rb | 36 +++++-------------- app/controllers/newflow/login_controller.rb | 12 ++----- .../newflow/password_management_controller.rb | 4 +++ app/controllers/newflow/signup_controller.rb | 32 +++-------------- .../newflow/social_auth_controller.rb | 16 ++------- .../newflow/student_signup_controller.rb | 16 ++------- .../newflow/base/profile_newflow.html.erb | 6 +++- 9 files changed, 46 insertions(+), 98 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ac2a23902..a93db020b8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,8 +45,24 @@ def init_posthog host: "https://us.i.posthog.com", on_error: Proc.new { |status, msg| print msg } }) + end - @posthog.logger.level = Logger::DEBUG + def log_posthog(user, event) + return if user.nil? + @posthog.capture({ + distinct_id: user.uuid, + event: event, + properties: { + '$set': { email: user.email_addresses&.first&.value, + name: user.full_name, + role: user.role, + faculty_status: user.faculty_status, + school: user.school&.name, + last_authentication_provider: user.authentication&.last.provider, + authentication_count: user.authentication&.count, + } + } + }) end respond_to :html diff --git a/app/controllers/external_user_credentials_controller.rb b/app/controllers/external_user_credentials_controller.rb index 1576c815b3..b2be89b440 100644 --- a/app/controllers/external_user_credentials_controller.rb +++ b/app/controllers/external_user_credentials_controller.rb @@ -11,6 +11,7 @@ def create CreateExternalUserCredentials, success: -> { security_log :student_created_password + log_posthog(user, "user_created_with_external_credentials") redirect_to @return_to }, failure: -> { @@ -41,8 +42,7 @@ def render_form def authenticate_external_user! @user = User.find_by(id: Doorkeeper::AccessToken.find_by(token: params[:token])&.resource_owner_id) - - @posthog.capture({ distinct_id: @user.uuid, event: 'user_external_authentication' }) + log_posthog(user, "user_external_authentication") # Cannot be used by users who can already login raise SecurityTransgression if @user.nil? || !@user.is_external? diff --git a/app/controllers/newflow/educator_signup_controller.rb b/app/controllers/newflow/educator_signup_controller.rb index 91a867f55e..b9bf3c58df 100644 --- a/app/controllers/newflow/educator_signup_controller.rb +++ b/app/controllers/newflow/educator_signup_controller.rb @@ -43,13 +43,8 @@ def educator_signup @user = @handler_result.outputs.user save_unverified_user(@user.id) security_log(:educator_began_signup, { user: @user }) - @posthog.capture({ - distinct_id: @user.uuid, - event: 'educator_started_signup', - properties: { - '$set': { email: @user.email_addresses.first.value , name: @user.full_name, phone: @user.phone_number, faculty_status: @user.faculty_status } - } - }) + + log_posthog(user, 'educator_started_signup') clear_cache_BRI_marketing redirect_to(educator_email_verification_form_path) }, @@ -99,13 +94,7 @@ def educator_verify_email_by_pin clear_unverified_user sign_in!(@handler_result.outputs.user) security_log(:educator_verified_email, email:@email) - @posthog.capture({ - distinct_id: user.uuid, - event: 'educator_verified_email', - properties: { - '$set': { email: current_user.email_addresses.first.value , name: current_user.full_name, faculty_status: current_user.faculty_status } - } - }) + log_posthog(user, 'educator_verified_email') redirect_to(educator_sheerid_form_path) }, failure: lambda { @@ -120,13 +109,7 @@ def educator_verify_email_by_pin def educator_sheerid_form @sheerid_url = generate_sheer_id_url(user: current_user) - @posthog.capture({ - distinct_id: current_user.uuid, - event: 'educator_view_sheer_id_form', - properties: { - '$set': { email: current_user.email_addresses.first.value , name: current_user.full_name, faculty_status: current_user.faculty_status } - } - }) + log_posthog(user, 'educator_view_sheer_id_form') security_log(:user_viewed_sheerid_form, user: current_user) end @@ -138,6 +121,7 @@ def sheerid_webhook verification_id: sheerid_provided_verification_id_param, success: lambda { security_log(:sheerid_webhook_received, { data: @handler_result }) + log_posthog(user, 'educator_sheerid_webhook_received') render(status: :ok, plain: 'Success') }, failure: lambda { @@ -157,6 +141,7 @@ def sheerid_webhook def educator_profile_form @book_titles = book_data.titles security_log(:user_viewed_profile_form, form_name: action_name, user: current_user) + log_posthog(user, 'educator_viewed_profile_form') end def educator_complete_profile @@ -165,13 +150,7 @@ def educator_complete_profile user: current_user, success: lambda { user = @handler_result.outputs.user - @posthog.capture({ - distinct_id: user.uuid, - event: 'educator_completed_profile', - properties: { - '$set': { school: current_user.school.name, faculty_status: current_user.faculty_status } - } - }) + log_posthog(user, 'educator_complete_profile') security_log(:user_profile_complete, { user: user }) clear_incomplete_educator @@ -184,6 +163,7 @@ def educator_complete_profile failure: lambda { @book_titles = book_data.titles security_log(:educator_sign_up_failed, user: current_user, reason: @handler_result.errors) + log_posthog(user, 'educator_complete_profile_failed') if @handler_result.outputs.is_on_cs_form redirect_to(educator_cs_verification_form_url, alert: "Please check your input and try again. Email address and School Name are required fields.") else diff --git a/app/controllers/newflow/login_controller.rb b/app/controllers/newflow/login_controller.rb index 2305be321f..36d381e6bc 100644 --- a/app/controllers/newflow/login_controller.rb +++ b/app/controllers/newflow/login_controller.rb @@ -20,13 +20,7 @@ def login user = @handler_result.outputs.user Sentry.set_user(id: user.id) if Rails.env.production? - @posthog.capture({ - distinct_id: user.uuid, - event: 'user_logged_in', - properties: { - '$set': { email: user.email_addresses.first.value , name: user.full_name } - } - }) + log_posthog(user, 'user_logged_in') if user.unverified? save_unverified_user(user.id) @@ -59,15 +53,13 @@ def login security_log(:sign_in_failed, { reason: code, email: email, user: user }) end - @posthog.capture({ distinct_id: email, event: 'user_login_failed'}) - render :login_form } ) end def logout - @posthog.capture({ distinct_id: current_user.uuid, event: 'user_logged_out'}) + log_posthog(user, 'user_logged_out') sign_out! Sentry.set_user({}) if Rails.env.production? redirect_back(fallback_location: newflow_login_path) diff --git a/app/controllers/newflow/password_management_controller.rb b/app/controllers/newflow/password_management_controller.rb index c81f565751..d58567ec86 100644 --- a/app/controllers/newflow/password_management_controller.rb +++ b/app/controllers/newflow/password_management_controller.rb @@ -10,6 +10,10 @@ class PasswordManagementController < BaseController def forgot_password_form @email = login_failed_email + user = ContactInfo.find_by(value: @email)&.user + unless user.nil? + log_posthog(user, 'user_forgot_password') + end end def send_reset_password_email diff --git a/app/controllers/newflow/signup_controller.rb b/app/controllers/newflow/signup_controller.rb index ff2df3a62b..2aeccbd9c7 100644 --- a/app/controllers/newflow/signup_controller.rb +++ b/app/controllers/newflow/signup_controller.rb @@ -21,23 +21,11 @@ def verify_email_by_code if user.student? security_log(:student_verified_email, {user: user, message: "Student verified email."}) - @posthog.capture({ - distinct_id: user.uuid, - event: 'student_verified_email', - properties: { - '$set': { email: user.email_addresses.first.value , name: user.full_name } - } - }) + log_posthog(user, 'student_verified_email') redirect_to signup_done_path else security_log(:educator_verified_email, {user: user, message: "Educator verified email."}) - @posthog.capture({ - distinct_id: user.uuid, - event: 'educator_verified_email', - properties: { - '$set': { email: user.email_addresses.first.value , name: user.full_name } - } - }) + log_posthog(user, 'educator_verified_email') redirect_to(educator_sheerid_form_path) end }, @@ -49,13 +37,7 @@ def verify_email_by_code def signup_done security_log(:user_viewed_signup_form, form_name: action_name) - @posthog.capture({ - distinct_id: current_user.uuid, - event: 'user_completed_signup', - properties: { - '$set': { email: current_user.email_addresses.first.value , name: current_user.full_name } - } - }) + log_posthog(user, 'user_signup_done') @first_name = current_user.first_name @email_address = current_user.email_addresses.first&.value end @@ -70,13 +52,7 @@ def skip_signup_done_for_tutor_users def exit_newflow_signup_if_logged_in if signed_in? - @posthog.capture({ - distinct_id: current_user.uuid, - event: 'user_redirected_because_signed_in', - properties: { - '$set': { email: current_user.email_addresses.first.value , name: current_user.full_name } - } - }) + log_posthog(user, 'user_redirected_because_signed_in') redirect_back(fallback_location: profile_newflow_path(request.query_parameters)) end end diff --git a/app/controllers/newflow/social_auth_controller.rb b/app/controllers/newflow/social_auth_controller.rb index cb303c49fe..2a0568d98a 100644 --- a/app/controllers/newflow/social_auth_controller.rb +++ b/app/controllers/newflow/social_auth_controller.rb @@ -51,13 +51,7 @@ def oauth_callback end sign_in!(user) - @posthog.capture({ - distinct_id: user.uuid, - event: 'user_Logged_in_with_social', - properties: { - '$set': { email: user.email_addresses.first.value , name: user.full_name, authentication_provider: authentication.provider } - } - }) + log_posthog(user, "user_logged_in_with_#{authentication.provider}") security_log(:authenticated_with_social, user: user, authentication_id: authentication.id) redirect_back(fallback_location: profile_newflow_path) @@ -69,13 +63,7 @@ def oauth_callback code = @handler_result.errors.first.code authentication = @handler_result.outputs.authentication - @posthog.capture({ - distinct_id: @email, - event: 'user_Logged_in_with_social_failed', - properties: { - '$set': { email: @email, authentication_provider: authentication.provider } - } - }) + log_posthog(user, "user_logged_in_with_#{authentication.provider}_failed") case code when :should_redirect_to_signup diff --git a/app/controllers/newflow/student_signup_controller.rb b/app/controllers/newflow/student_signup_controller.rb index 2f8855b06e..5176bddd26 100644 --- a/app/controllers/newflow/student_signup_controller.rb +++ b/app/controllers/newflow/student_signup_controller.rb @@ -19,13 +19,7 @@ def student_signup user = @handler_result.outputs.user save_unverified_user(user.id) security_log(:student_signed_up, { user: user }) - @posthog.capture({ - distinct_id: user.uuid, - event: 'student_started_signup', - properties: { - '$set': { email: user.email_addresses.first.value, name: user.full_name } - } - }) + log_posthog(user, "student_started_signup") redirect_to student_email_verification_form_path }, failure: lambda { @@ -73,13 +67,7 @@ def student_verify_email_by_pin user = @handler_result.outputs.user sign_in!(user) security_log(:student_verified_email) - @posthog.capture({ - distinct_id: user.uuid, - event: 'student_verified_email', - properties: { - '$set': { email: user.email_addresses.first.value, name: user.full_name } - } - }) + log_posthog(user, "student_verified_email") redirect_to(signup_done_path) }, failure: lambda { diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index 49dcb74e67..a0a7f7f04a 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -9,7 +9,11 @@ posthog.capture('user_visits_profile'); posthog.identify( '<%= current_user.uuid %>', - { email: '<%= current_user.email_addresses.first.value %>', name: '<%= current_user.full_name %>' }, + { email: '<%= current_user.email_addresses.first.value %>', + name: '<%= current_user.full_name %>', + faculty_status: '<%= current_user.faculty_status %>', + role: '<%= current_user.role %>', + school: '<%= current_user.school.name %>'}, ); <% end %> From adfdb974b496b9a7d3014b0bdc6dbcd1c4798545 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 17:50:19 -0600 Subject: [PATCH 03/28] variable --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a93db020b8..75b5d85df5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -58,8 +58,8 @@ def log_posthog(user, event) role: user.role, faculty_status: user.faculty_status, school: user.school&.name, - last_authentication_provider: user.authentication&.last.provider, - authentication_count: user.authentication&.count, + recent_authentication_provider: user.authentications&.last&.provider, + authentication_method_count: user.authentications&.count } } }) From 4d14b236e1982772a58c442b4e4e3dc655ee8ec9 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 20:16:12 -0600 Subject: [PATCH 04/28] more educator events --- app/controllers/newflow/educator_signup_controller.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/newflow/educator_signup_controller.rb b/app/controllers/newflow/educator_signup_controller.rb index b9bf3c58df..6e12e21479 100644 --- a/app/controllers/newflow/educator_signup_controller.rb +++ b/app/controllers/newflow/educator_signup_controller.rb @@ -43,7 +43,6 @@ def educator_signup @user = @handler_result.outputs.user save_unverified_user(@user.id) security_log(:educator_began_signup, { user: @user }) - log_posthog(user, 'educator_started_signup') clear_cache_BRI_marketing redirect_to(educator_email_verification_form_path) @@ -102,6 +101,7 @@ def educator_verify_email_by_pin @first_name = unverified_user.first_name @email = unverified_user.email_addresses.first.value security_log(:educator_verify_email_failed, email: @email) + log_posthog(user, "educator_verified_email_failed") render(:educator_email_verification_form) } ) @@ -126,6 +126,7 @@ def sheerid_webhook }, failure: lambda { security_log(:sheerid_webhook_failed, { data: @handler_result }) + log_posthog(user, 'educator_sheerid_webhook_failed') Sentry.capture_message( '[SheerID Webhook] Failed!', extra: { @@ -176,13 +177,7 @@ def educator_complete_profile def educator_pending_cs_verification security_log(:user_sent_to_cs_for_review, user: current_user) @email_address = current_user.email_addresses.last&.value - @posthog.capture({ - distinct_id: current_user.uuid, - event: 'educator_pending_manual_verification', - properties: { - '$set': { email: @email_address , name: current_user.full_name, faculty_status: current_user.faculty_status } - } - }) + log_posthog(user, 'educator_sent_to_cs_for_review') end private ################# From deb058f826c4eb35f372c16affff88b38b359f2b Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 20:23:02 -0600 Subject: [PATCH 05/28] update user vars --- .../external_user_credentials_controller.rb | 2 +- .../newflow/educator_signup_controller.rb | 16 +++++++--------- app/controllers/newflow/login_controller.rb | 2 +- app/controllers/newflow/signup_controller.rb | 4 ++-- .../newflow/social_auth_controller.rb | 10 +--------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/controllers/external_user_credentials_controller.rb b/app/controllers/external_user_credentials_controller.rb index b2be89b440..16152e23d2 100644 --- a/app/controllers/external_user_credentials_controller.rb +++ b/app/controllers/external_user_credentials_controller.rb @@ -42,7 +42,7 @@ def render_form def authenticate_external_user! @user = User.find_by(id: Doorkeeper::AccessToken.find_by(token: params[:token])&.resource_owner_id) - log_posthog(user, "user_external_authentication") + log_posthog(@user, "user_external_authentication") # Cannot be used by users who can already login raise SecurityTransgression if @user.nil? || !@user.is_external? diff --git a/app/controllers/newflow/educator_signup_controller.rb b/app/controllers/newflow/educator_signup_controller.rb index 6e12e21479..0ac9c7e754 100644 --- a/app/controllers/newflow/educator_signup_controller.rb +++ b/app/controllers/newflow/educator_signup_controller.rb @@ -43,7 +43,7 @@ def educator_signup @user = @handler_result.outputs.user save_unverified_user(@user.id) security_log(:educator_began_signup, { user: @user }) - log_posthog(user, 'educator_started_signup') + log_posthog(@user, 'educator_started_signup') clear_cache_BRI_marketing redirect_to(educator_email_verification_form_path) }, @@ -93,7 +93,7 @@ def educator_verify_email_by_pin clear_unverified_user sign_in!(@handler_result.outputs.user) security_log(:educator_verified_email, email:@email) - log_posthog(user, 'educator_verified_email') + log_posthog(@handler_result.outputs.user, 'educator_verified_email') redirect_to(educator_sheerid_form_path) }, failure: lambda { @@ -101,7 +101,7 @@ def educator_verify_email_by_pin @first_name = unverified_user.first_name @email = unverified_user.email_addresses.first.value security_log(:educator_verify_email_failed, email: @email) - log_posthog(user, "educator_verified_email_failed") + log_posthog(unverified_user, "educator_verified_email_failed") render(:educator_email_verification_form) } ) @@ -109,7 +109,7 @@ def educator_verify_email_by_pin def educator_sheerid_form @sheerid_url = generate_sheer_id_url(user: current_user) - log_posthog(user, 'educator_view_sheer_id_form') + log_posthog(current_user, 'educator_view_sheer_id_form') security_log(:user_viewed_sheerid_form, user: current_user) end @@ -121,12 +121,10 @@ def sheerid_webhook verification_id: sheerid_provided_verification_id_param, success: lambda { security_log(:sheerid_webhook_received, { data: @handler_result }) - log_posthog(user, 'educator_sheerid_webhook_received') render(status: :ok, plain: 'Success') }, failure: lambda { security_log(:sheerid_webhook_failed, { data: @handler_result }) - log_posthog(user, 'educator_sheerid_webhook_failed') Sentry.capture_message( '[SheerID Webhook] Failed!', extra: { @@ -142,7 +140,7 @@ def sheerid_webhook def educator_profile_form @book_titles = book_data.titles security_log(:user_viewed_profile_form, form_name: action_name, user: current_user) - log_posthog(user, 'educator_viewed_profile_form') + log_posthog(current_user, 'educator_viewed_profile_form') end def educator_complete_profile @@ -164,7 +162,7 @@ def educator_complete_profile failure: lambda { @book_titles = book_data.titles security_log(:educator_sign_up_failed, user: current_user, reason: @handler_result.errors) - log_posthog(user, 'educator_complete_profile_failed') + log_posthog(current_user, 'educator_complete_profile_failed') if @handler_result.outputs.is_on_cs_form redirect_to(educator_cs_verification_form_url, alert: "Please check your input and try again. Email address and School Name are required fields.") else @@ -177,7 +175,7 @@ def educator_complete_profile def educator_pending_cs_verification security_log(:user_sent_to_cs_for_review, user: current_user) @email_address = current_user.email_addresses.last&.value - log_posthog(user, 'educator_sent_to_cs_for_review') + log_posthog(current_user, 'educator_sent_to_cs_for_review') end private ################# diff --git a/app/controllers/newflow/login_controller.rb b/app/controllers/newflow/login_controller.rb index 36d381e6bc..70e60de728 100644 --- a/app/controllers/newflow/login_controller.rb +++ b/app/controllers/newflow/login_controller.rb @@ -59,7 +59,7 @@ def login end def logout - log_posthog(user, 'user_logged_out') + log_posthog(current_user, 'user_logged_out') sign_out! Sentry.set_user({}) if Rails.env.production? redirect_back(fallback_location: newflow_login_path) diff --git a/app/controllers/newflow/signup_controller.rb b/app/controllers/newflow/signup_controller.rb index 2aeccbd9c7..ca65373dcf 100644 --- a/app/controllers/newflow/signup_controller.rb +++ b/app/controllers/newflow/signup_controller.rb @@ -37,7 +37,7 @@ def verify_email_by_code def signup_done security_log(:user_viewed_signup_form, form_name: action_name) - log_posthog(user, 'user_signup_done') + log_posthog(current_user, 'user_signup_done') @first_name = current_user.first_name @email_address = current_user.email_addresses.first&.value end @@ -52,7 +52,7 @@ def skip_signup_done_for_tutor_users def exit_newflow_signup_if_logged_in if signed_in? - log_posthog(user, 'user_redirected_because_signed_in') + log_posthog(current_user, 'user_redirected_because_signed_in') redirect_back(fallback_location: profile_newflow_path(request.query_parameters)) end end diff --git a/app/controllers/newflow/social_auth_controller.rb b/app/controllers/newflow/social_auth_controller.rb index 2a0568d98a..ddd69a950b 100644 --- a/app/controllers/newflow/social_auth_controller.rb +++ b/app/controllers/newflow/social_auth_controller.rb @@ -39,13 +39,7 @@ def oauth_callback @last_name = user.last_name @email = @handler_result.outputs.email security_log(:student_social_sign_up, user: user, authentication_id: authentication.id) - @posthog.capture({ - distinct_id: user.uuid, - event: 'student_signup_with_social', - properties: { - '$set': { email: user.email_addresses.first.value , name: user.full_name, authentication_provider: authentication.provider } - } - }) + log_posthog(user, "student_signup_#{authentication.provider}") # must confirm their social info on signup render :confirm_social_info_form and return # TODO: if possible, update the route/path to reflect that this page is being rendered end @@ -63,8 +57,6 @@ def oauth_callback code = @handler_result.errors.first.code authentication = @handler_result.outputs.authentication - log_posthog(user, "user_logged_in_with_#{authentication.provider}_failed") - case code when :should_redirect_to_signup redirect_to( From 9d2ea77ecab614c918865abc7fafbd3a54d44198 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 20:44:43 -0600 Subject: [PATCH 06/28] return if tests --- app/controllers/application_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 75b5d85df5..ca8d61d978 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,6 +39,7 @@ def return_url_specified_and_allowed? def init_posthog + return if Rails.env.test? require 'posthog-ruby' @posthog = PostHog::Client.new({ api_key: Rails.application.secrets.posthog_project_api_key, @@ -48,7 +49,7 @@ def init_posthog end def log_posthog(user, event) - return if user.nil? + return if user.nil? or Rails.env.test? @posthog.capture({ distinct_id: user.uuid, event: event, From de2ac9fca48c9faa531aa67b2dba9af6f0367aa7 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 22:18:51 -0600 Subject: [PATCH 07/28] always profile --- app/views/layouts/_posthog.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index ecb5a36b51..1ed2e220eb 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -2,6 +2,6 @@ !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug getPageViewId".split(" "),n=0;n', { api_host:'https://us.i.posthog.com', - person_profiles: 'identified_only' + person_profiles: 'always' }) From 8b7b9877b782939998b15145811fb9ea66ccda2b Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 22:24:54 -0600 Subject: [PATCH 08/28] handle current_user being nil --- .../newflow/base/profile_newflow.html.erb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index a0a7f7f04a..9bb9086b6a 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -1,6 +1,6 @@ <% @parent_col_id = "profile" - @using_os = current_user.using_openstax + @using_os = current_user&.using_openstax %> <% content_for :head do %> @@ -8,12 +8,12 @@ <% end %> @@ -209,10 +209,10 @@ $('#username').editable({ }); OX.Profile.Name.editable($('#name'), { - title: "<%= current_user.title %>", - first_name: "<%= current_user.first_name %>", - last_name: "<%= current_user.last_name %>", - suffix: "<%= current_user.suffix %>" + title: "<%= current_user&.title %>", + first_name: "<%= current_user&.first_name %>", + last_name: "<%= current_user&.last_name %>", + suffix: "<%= current_user&.suffix %>" }); <% end # javscript content block %> From 73e8f527893e9ef1495e2a1f490a9a17edbf0a0e Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 22:34:04 -0600 Subject: [PATCH 09/28] remove log --- app/controllers/external_user_credentials_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/external_user_credentials_controller.rb b/app/controllers/external_user_credentials_controller.rb index 16152e23d2..9839d3d14d 100644 --- a/app/controllers/external_user_credentials_controller.rb +++ b/app/controllers/external_user_credentials_controller.rb @@ -42,7 +42,6 @@ def render_form def authenticate_external_user! @user = User.find_by(id: Doorkeeper::AccessToken.find_by(token: params[:token])&.resource_owner_id) - log_posthog(@user, "user_external_authentication") # Cannot be used by users who can already login raise SecurityTransgression if @user.nil? || !@user.is_external? From 971d79f7a838a9aea2f75b957f7dc6e60b103076 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 23:08:41 -0600 Subject: [PATCH 10/28] another null --- app/controllers/external_user_credentials_controller.rb | 1 + app/views/newflow/base/profile_newflow.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/external_user_credentials_controller.rb b/app/controllers/external_user_credentials_controller.rb index 9839d3d14d..16152e23d2 100644 --- a/app/controllers/external_user_credentials_controller.rb +++ b/app/controllers/external_user_credentials_controller.rb @@ -42,6 +42,7 @@ def render_form def authenticate_external_user! @user = User.find_by(id: Doorkeeper::AccessToken.find_by(token: params[:token])&.resource_owner_id) + log_posthog(@user, "user_external_authentication") # Cannot be used by users who can already login raise SecurityTransgression if @user.nil? || !@user.is_external? diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index 9bb9086b6a..d2dff67615 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -13,7 +13,7 @@ name: '<%= current_user&.full_name %>', faculty_status: '<%= current_user&.faculty_status %>', role: '<%= current_user&.role %>', - school: '<%= current_user&.school.name %>'}, + school: '<%= current_user&.school&.name %>'}, ); <% end %> From 70794d8a0663c9a046f7423d2408fe648696efdc Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Fri, 31 Jan 2025 23:20:43 -0600 Subject: [PATCH 11/28] remove event --- app/controllers/external_user_credentials_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/external_user_credentials_controller.rb b/app/controllers/external_user_credentials_controller.rb index 16152e23d2..9839d3d14d 100644 --- a/app/controllers/external_user_credentials_controller.rb +++ b/app/controllers/external_user_credentials_controller.rb @@ -42,7 +42,6 @@ def render_form def authenticate_external_user! @user = User.find_by(id: Doorkeeper::AccessToken.find_by(token: params[:token])&.resource_owner_id) - log_posthog(@user, "user_external_authentication") # Cannot be used by users who can already login raise SecurityTransgression if @user.nil? || !@user.is_external? From f15989be85a790b13d2895e8a95d257d1736a9c4 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 01:19:18 -0600 Subject: [PATCH 12/28] profile students --- .../student_email_verification_form.html.erb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/views/newflow/student_signup/student_email_verification_form.html.erb b/app/views/newflow/student_signup/student_email_verification_form.html.erb index 319d9d1e37..2ed0754999 100644 --- a/app/views/newflow/student_signup/student_email_verification_form.html.erb +++ b/app/views/newflow/student_signup/student_email_verification_form.html.erb @@ -26,6 +26,20 @@ ).html_safe %> +<% content_for :head do %> + +<% end %> + <%= render( partial: 'newflow/signup/email_verification_form_template', From 5befe0d508c045071097956c081d8aa913eda20d Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 10:16:02 -0600 Subject: [PATCH 13/28] use school id --- app/controllers/application_controller.rb | 2 +- .../student_signup/student_email_verification_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ca8d61d978..cd0efd61e9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -58,7 +58,7 @@ def log_posthog(user, event) name: user.full_name, role: user.role, faculty_status: user.faculty_status, - school: user.school&.name, + school: user.school&.id, recent_authentication_provider: user.authentications&.last&.provider, authentication_method_count: user.authentications&.count } diff --git a/app/views/newflow/student_signup/student_email_verification_form.html.erb b/app/views/newflow/student_signup/student_email_verification_form.html.erb index 2ed0754999..91f890783d 100644 --- a/app/views/newflow/student_signup/student_email_verification_form.html.erb +++ b/app/views/newflow/student_signup/student_email_verification_form.html.erb @@ -35,7 +35,7 @@ name: '<%= current_user&.full_name %>', faculty_status: '<%= current_user&.faculty_status %>', role: '<%= current_user&.role %>', - school: '<%= current_user&.school&.name %>'}, + school: '<%= current_user&.school&.id %>'}, ); <% end %> From 5dfb6c487fa20207851d6c76cdd2301d1c1b298e Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 10:47:55 -0600 Subject: [PATCH 14/28] no event required on signup done --- app/views/newflow/signup/_signup_done_template.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/newflow/signup/_signup_done_template.html.erb b/app/views/newflow/signup/_signup_done_template.html.erb index 0ff6413213..323e59ba1c 100644 --- a/app/views/newflow/signup/_signup_done_template.html.erb +++ b/app/views/newflow/signup/_signup_done_template.html.erb @@ -32,7 +32,6 @@ <%= content_for :page_specific do %> <% end %> From 93431ac438b5ce2667cf85fc903ddb4f80048125 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 11:43:13 -0600 Subject: [PATCH 18/28] remove student verify identify call --- .../student_email_verification_form.html.erb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/views/newflow/student_signup/student_email_verification_form.html.erb b/app/views/newflow/student_signup/student_email_verification_form.html.erb index 0c7b6d7052..319d9d1e37 100644 --- a/app/views/newflow/student_signup/student_email_verification_form.html.erb +++ b/app/views/newflow/student_signup/student_email_verification_form.html.erb @@ -26,17 +26,6 @@ ).html_safe %> -<% content_for :head do %> - -<% end %> - <%= render( partial: 'newflow/signup/email_verification_form_template', From 6415c6d33cc9deb96914b74778ca6dcabb82854a Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 12:22:51 -0600 Subject: [PATCH 19/28] add uuid to person --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d160a279ff..ed2b6934ea 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -57,6 +57,7 @@ def log_posthog(user, event) properties: { '$set': { email: user.email_addresses&.first&.value, name: user.full_name, + uuid: user.uuid, role: user.role, faculty_status: user.faculty_status, school: user.school&.id, From c560cfa59499d7441d0276046bfd3d747a2f0a55 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 16:09:28 -0600 Subject: [PATCH 20/28] refactor posthog init --- app/controllers/application_controller.rb | 19 ++++--------------- config/initializers/posthog.rb | 7 +++++++ 2 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 config/initializers/posthog.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ed2b6934ea..eefa96f02d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,6 @@ class ApplicationController < ActionController::Base before_action :authenticate_user! before_action :complete_signup_profile before_action :check_if_password_expired - before_action :init_posthog fine_print_require :general_terms_of_use, :privacy_policy, unless: :disable_fine_print @@ -35,19 +34,7 @@ def return_url_specified_and_allowed? end include Lev::HandleWith - - - - def init_posthog - return if Rails.env.test? - require 'posthog-ruby' - @posthog = PostHog::Client.new({ - api_key: Rails.application.secrets.posthog_project_api_key, - host: "https://us.i.posthog.com", - on_error: Proc.new { |status, msg| print msg } - }) - end - + def log_posthog(user, event) return if user.nil? or Rails.env.test? begin @@ -62,7 +49,9 @@ def log_posthog(user, event) faculty_status: user.faculty_status, school: user.school&.id, recent_authentication_provider: user.authentications&.last&.provider, - authentication_method_count: user.authentications&.count + authentication_method_count: user.authentications&.count, + salesforce_contact_id: user.salesforce_contact_id, + salesforce_lead_id: user.salesforce_lead_id, } } }) diff --git a/config/initializers/posthog.rb b/config/initializers/posthog.rb new file mode 100644 index 0000000000..538ee27fb6 --- /dev/null +++ b/config/initializers/posthog.rb @@ -0,0 +1,7 @@ +require 'posthog-ruby' + +@posthog = PostHog::Client.new({ + api_key: Rails.application.secrets.posthog_project_api_key, + host: "https://us.i.posthog.com", + on_error: Proc.new { |status, msg| print msg } +}) \ No newline at end of file From 287a0758adcc6a9adf64814d55181dc3d53a40ed Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 17:24:33 -0600 Subject: [PATCH 21/28] config --- app/controllers/application_controller.rb | 12 +++++++++++- app/views/newflow/base/profile_newflow.html.erb | 17 ++++++++++++----- config/initializers/posthog.rb | 8 +++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eefa96f02d..82eb96bf2d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,13 @@ +require 'posthog-ruby' + +@posthog = PostHog::Client.new( + api_key: Rails.application.secrets.posthog_project_api_key, + host: "https://us.i.posthog.com", + on_error: Proc.new { |status, msg| print msg }, + disabled: Rails.env.test?, + async: true, +) + class ApplicationController < ActionController::Base layout 'application' @@ -34,7 +44,7 @@ def return_url_specified_and_allowed? end include Lev::HandleWith - + def log_posthog(user, event) return if user.nil? or Rails.env.test? begin diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index d2dff67615..c043e6f9e2 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -9,11 +9,18 @@ posthog.capture('user_visits_profile'); posthog.identify( '<%= current_user&.uuid %>', - { email: '<%= current_user&.email_addresses&.first&.value %>', - name: '<%= current_user&.full_name %>', - faculty_status: '<%= current_user&.faculty_status %>', - role: '<%= current_user&.role %>', - school: '<%= current_user&.school&.name %>'}, + { + email: "<%= current_user&.email_addresses&.first&.value %>", + name: "<%= current_user&.full_name %>", + uuid: "<%= current_user&.uuid %>", + faculty_status: "<%= current_user&.faculty_status %>", + role: "<%= current_user&.role %>", + school: "<%= current_user&.school&.name %>", + recent_authentication_provider: "<%= current_user&.authentications&.last&.provider %>", + authentication_method_count: <%= current_user&.authentications&.count || 0 %>, + salesforce_contact_id: "<%= current_user&.salesforce_contact_id %>", + salesforce_lead_id: "<%= current_user&.salesforce_lead_id %>" + } ); <% end %> diff --git a/config/initializers/posthog.rb b/config/initializers/posthog.rb index 538ee27fb6..e15ffeecfa 100644 --- a/config/initializers/posthog.rb +++ b/config/initializers/posthog.rb @@ -1,7 +1,9 @@ require 'posthog-ruby' -@posthog = PostHog::Client.new({ +@posthog = PostHog::Client.new( api_key: Rails.application.secrets.posthog_project_api_key, host: "https://us.i.posthog.com", - on_error: Proc.new { |status, msg| print msg } -}) \ No newline at end of file + on_error: Proc.new { |status, msg| print msg }, + disabled: Rails.env.test?, + async: true, +) From 05d9922b8c40654a451c4ba04557b10cebcc0c19 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 17:44:18 -0600 Subject: [PATCH 22/28] revert --- app/controllers/application_controller.rb | 29 ++++++++++--------- .../newflow/base/profile_newflow.html.erb | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 82eb96bf2d..d628f0b235 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,19 +1,10 @@ -require 'posthog-ruby' - -@posthog = PostHog::Client.new( - api_key: Rails.application.secrets.posthog_project_api_key, - host: "https://us.i.posthog.com", - on_error: Proc.new { |status, msg| print msg }, - disabled: Rails.env.test?, - async: true, -) - class ApplicationController < ActionController::Base layout 'application' before_action :authenticate_user! before_action :complete_signup_profile before_action :check_if_password_expired + before_action :init_posthog fine_print_require :general_terms_of_use, :privacy_policy, unless: :disable_fine_print @@ -45,9 +36,19 @@ def return_url_specified_and_allowed? include Lev::HandleWith + def init_posthog + return if Rails.env.test? + require 'posthog-ruby' + @posthog = PostHog::Client.new({ + api_key: Rails.application.secrets.posthog_project_api_key, + host: "https://us.i.posthog.com", + on_error: Proc.new { |status, msg| print msg } + }) + end + def log_posthog(user, event) return if user.nil? or Rails.env.test? - begin + # begin @posthog.capture({ distinct_id: user.uuid, event: event, @@ -65,9 +66,9 @@ def log_posthog(user, event) } } }) - rescue StandardError => e - Rails.logger.error("PostHog tracking error: #{e.message}") - end + # rescue StandardError => e + # Rails.logger.error("PostHog tracking error: #{e.message}") + # end end respond_to :html diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index c043e6f9e2..bd7bbff01d 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -17,7 +17,7 @@ role: "<%= current_user&.role %>", school: "<%= current_user&.school&.name %>", recent_authentication_provider: "<%= current_user&.authentications&.last&.provider %>", - authentication_method_count: <%= current_user&.authentications&.count || 0 %>, + authentication_method_count: "<%= current_user&.authentications&.count %>", salesforce_contact_id: "<%= current_user&.salesforce_contact_id %>", salesforce_lead_id: "<%= current_user&.salesforce_lead_id %>" } From 863ef6cd410cb8095313df548c055e1269c456f5 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sat, 1 Feb 2025 21:41:27 -0600 Subject: [PATCH 23/28] admin/error analytics --- app/views/layouts/_posthog.html.erb | 2 +- app/views/layouts/admin.html.erb | 2 ++ app/views/layouts/application.html.erb | 2 +- app/views/layouts/static_error.html.erb | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index 1ed2e220eb..f7094fb18c 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -1,4 +1,4 @@ - + + <%= render partial: 'layouts/posthog' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 37ccb1d2b4..8a8e589db6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,7 +17,7 @@ - <%= stylesheet_link_tag "application" %> + <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> diff --git a/app/views/layouts/static_error.html.erb b/app/views/layouts/static_error.html.erb index 8f519a77c7..fcdf2682c2 100644 --- a/app/views/layouts/static_error.html.erb +++ b/app/views/layouts/static_error.html.erb @@ -11,6 +11,7 @@ <%= @page_title + ' - ' if !@page_title.nil? %><%= PAGE_TITLE_SUFFIX %> + <%= render partial: 'layouts/posthog' %> From e5becdc0ac56308a1b322be3443b126acc550718 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sun, 2 Feb 2025 13:56:19 -0600 Subject: [PATCH 24/28] identified only users --- app/views/layouts/_posthog.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index f7094fb18c..13976f7fac 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -2,6 +2,6 @@ !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug getPageViewId".split(" "),n=0;n', { api_host:'https://us.i.posthog.com', - person_profiles: 'always' + person_profiles: 'identified_only' }) From ea9eec5ab4edac915510410b9e6a6795ba7abf12 Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sun, 2 Feb 2025 14:28:46 -0600 Subject: [PATCH 25/28] consolidate ident template calls --- app/views/layouts/_posthog.html.erb | 18 +++++++++++++++ .../newflow/base/profile_newflow.html.erb | 22 ------------------- .../signup/_signup_done_template.html.erb | 11 +--------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index 13976f7fac..5274366ab9 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -4,4 +4,22 @@ api_host:'https://us.i.posthog.com', person_profiles: 'identified_only' }) + + <% unless current_user.is_anonymous? %> + posthog.identify( + '<%= current_user&.uuid %>', + { + email: "<%= current_user&.email_addresses&.first&.value %>", + name: "<%= current_user&.full_name %>", + uuid: "<%= current_user&.uuid %>", + faculty_status: "<%= current_user&.faculty_status %>", + role: "<%= current_user&.role %>", + school: "<%= current_user&.school&.name %>", + recent_authentication_provider: "<%= current_user&.authentications&.last&.provider %>", + authentication_method_count: "<%= current_user&.authentications&.count %>", + salesforce_contact_id: "<%= current_user&.salesforce_contact_id %>", + salesforce_lead_id: "<%= current_user&.salesforce_lead_id %>" + } + ); + <% end %> diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index bd7bbff01d..c4130a1fc1 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -3,28 +3,6 @@ @using_os = current_user&.using_openstax %> -<% content_for :head do %> - <%= javascript_include_tag "profile" %> - -<% end %> -
<%= render(partial: 'layouts/main_menu') %>
diff --git a/app/views/newflow/signup/_signup_done_template.html.erb b/app/views/newflow/signup/_signup_done_template.html.erb index 323e59ba1c..71bfae845c 100644 --- a/app/views/newflow/signup/_signup_done_template.html.erb +++ b/app/views/newflow/signup/_signup_done_template.html.erb @@ -28,13 +28,4 @@ <% end %> - - -<%= content_for :page_specific do %> - -<% end %> \ No newline at end of file + \ No newline at end of file From 4a10662430008a528f0e7f59ff8ad56b9204cbcb Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sun, 2 Feb 2025 14:31:24 -0600 Subject: [PATCH 26/28] resume error handling --- app/controllers/application_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d628f0b235..d2d25ef4b3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,7 @@ def init_posthog def log_posthog(user, event) return if user.nil? or Rails.env.test? - # begin + begin @posthog.capture({ distinct_id: user.uuid, event: event, @@ -66,9 +66,9 @@ def log_posthog(user, event) } } }) - # rescue StandardError => e - # Rails.logger.error("PostHog tracking error: #{e.message}") - # end + rescue StandardError => e + Rails.logger.error("PostHog tracking error: #{e.message}") + end end respond_to :html From 23dab87de6db67e0bc7be51928053e6125a6c7ed Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sun, 2 Feb 2025 14:45:06 -0600 Subject: [PATCH 27/28] set up groups for schools --- app/views/layouts/_posthog.html.erb | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index 5274366ab9..2d74c2e12b 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -6,20 +6,25 @@ }) <% unless current_user.is_anonymous? %> - posthog.identify( - '<%= current_user&.uuid %>', - { - email: "<%= current_user&.email_addresses&.first&.value %>", - name: "<%= current_user&.full_name %>", - uuid: "<%= current_user&.uuid %>", - faculty_status: "<%= current_user&.faculty_status %>", - role: "<%= current_user&.role %>", - school: "<%= current_user&.school&.name %>", - recent_authentication_provider: "<%= current_user&.authentications&.last&.provider %>", - authentication_method_count: "<%= current_user&.authentications&.count %>", - salesforce_contact_id: "<%= current_user&.salesforce_contact_id %>", - salesforce_lead_id: "<%= current_user&.salesforce_lead_id %>" - } - ); + posthog.group('school', "<%= current_user&.school&.id %>", { + name: "<%= current_user&.school&.name %>", + salesforce_id: "<%= current_user&.school&.salesforce_id %>" + }); + + posthog.identify( + '<%= current_user&.uuid %>', + { + email: "<%= current_user&.email_addresses&.first&.value %>", + name: "<%= current_user&.full_name %>", + uuid: "<%= current_user&.uuid %>", + faculty_status: "<%= current_user&.faculty_status %>", + role: "<%= current_user&.role %>", + recent_authentication_provider: "<%= current_user&.authentications&.last&.provider %>", + authentication_method_count: "<%= current_user&.authentications&.count %>", + salesforce_school_id: "<%= current_user&.school&.salesforce_id %>", + salesforce_contact_id: "<%= current_user&.salesforce_contact_id %>", + salesforce_lead_id: "<%= current_user&.salesforce_lead_id %>" + } + ); <% end %> From 5a0c74e0c2e0785db9eb5fc086365c40b533cd3b Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Sun, 2 Feb 2025 14:58:29 -0600 Subject: [PATCH 28/28] fix profile --- app/views/layouts/_posthog.html.erb | 10 +++++++--- app/views/newflow/base/profile_newflow.html.erb | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/views/layouts/_posthog.html.erb b/app/views/layouts/_posthog.html.erb index 2d74c2e12b..67570c5477 100644 --- a/app/views/layouts/_posthog.html.erb +++ b/app/views/layouts/_posthog.html.erb @@ -1,3 +1,4 @@ +<% unless Rails.env.test? %> +<% end %> \ No newline at end of file diff --git a/app/views/newflow/base/profile_newflow.html.erb b/app/views/newflow/base/profile_newflow.html.erb index c4130a1fc1..42faf6ca9d 100644 --- a/app/views/newflow/base/profile_newflow.html.erb +++ b/app/views/newflow/base/profile_newflow.html.erb @@ -3,6 +3,10 @@ @using_os = current_user&.using_openstax %> +<% content_for :head do %> + <%= javascript_include_tag "profile" %> +<% end %> +
<%= render(partial: 'layouts/main_menu') %>