diff --git a/server/Gemfile b/server/Gemfile index df0b4c531..175543c96 100644 --- a/server/Gemfile +++ b/server/Gemfile @@ -56,9 +56,6 @@ gem 'graphiql-rails', '~> 1.8.0' gem 'rinku', '~> 2.0.6' gem 'sanitize', '~> 6.0.1' -#google analytics -gem 'staccato', '~> 0.5.3' - gem 'angular_rails_csrf', '~> 5.0.0' diff --git a/server/Gemfile.lock b/server/Gemfile.lock index 6ec3c2c7f..52b91d9a9 100644 --- a/server/Gemfile.lock +++ b/server/Gemfile.lock @@ -1,40 +1,40 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) + actioncable (6.1.7.4) + actionpack (= 6.1.7.4) + activesupport (= 6.1.7.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + actionmailbox (6.1.7.4) + actionpack (= 6.1.7.4) + activejob (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) mail (>= 2.7.1) - actionmailer (6.1.7.3) - actionpack (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activesupport (= 6.1.7.3) + actionmailer (6.1.7.4) + actionpack (= 6.1.7.4) + actionview (= 6.1.7.4) + activejob (= 6.1.7.4) + activesupport (= 6.1.7.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.7.3) - actionview (= 6.1.7.3) - activesupport (= 6.1.7.3) + actionpack (6.1.7.4) + actionview (= 6.1.7.4) + activesupport (= 6.1.7.4) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.3) - actionpack (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + actiontext (6.1.7.4) + actionpack (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) nokogiri (>= 1.8.5) - actionview (6.1.7.3) - activesupport (= 6.1.7.3) + actionview (6.1.7.4) + activesupport (= 6.1.7.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -44,22 +44,22 @@ GEM activemodel (>= 5.2.0) activestorage (>= 5.2.0) activesupport (>= 5.2.0) - activejob (6.1.7.3) - activesupport (= 6.1.7.3) + activejob (6.1.7.4) + activesupport (= 6.1.7.4) globalid (>= 0.3.6) - activemodel (6.1.7.3) - activesupport (= 6.1.7.3) - activerecord (6.1.7.3) - activemodel (= 6.1.7.3) - activesupport (= 6.1.7.3) - activestorage (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activesupport (= 6.1.7.3) + activemodel (6.1.7.4) + activesupport (= 6.1.7.4) + activerecord (6.1.7.4) + activemodel (= 6.1.7.4) + activesupport (= 6.1.7.4) + activestorage (6.1.7.4) + actionpack (= 6.1.7.4) + activejob (= 6.1.7.4) + activerecord (= 6.1.7.4) + activesupport (= 6.1.7.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.3) + activesupport (6.1.7.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -183,7 +183,7 @@ GEM promise.rb (~> 0.7.2) hashie (5.0.0) htmlentities (4.3.4) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) @@ -211,9 +211,9 @@ GEM listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.20.0) + loofah (2.21.3) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap @@ -224,12 +224,12 @@ GEM method_source (1.0.0) mini_magick (4.12.0) mini_mime (1.1.2) - minitest (5.18.0) + minitest (5.18.1) msgpack (1.7.0) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.3.0) - net-imap (0.3.4) + net-imap (0.3.6) date net-protocol net-pop (0.1.2) @@ -242,11 +242,11 @@ GEM net-protocol net-ssh (7.1.0) nio4r (2.5.9) - nokogiri (1.14.3-arm64-darwin) + nokogiri (1.15.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.14.3-x86_64-darwin) + nokogiri (1.15.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.14.3-x86_64-linux) + nokogiri (1.15.2-x86_64-linux) racc (~> 1.4) oauth2 (1.4.11) faraday (>= 0.17.3, < 3.0) @@ -291,7 +291,7 @@ GEM puma (5.6.4) nio4r (~> 2.0) raabro (1.4.0) - racc (1.6.2) + racc (1.7.1) rack (2.2.7) rack-cors (1.1.1) rack (>= 2.0.0) @@ -303,29 +303,30 @@ GEM rack rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7.3) - actioncable (= 6.1.7.3) - actionmailbox (= 6.1.7.3) - actionmailer (= 6.1.7.3) - actionpack (= 6.1.7.3) - actiontext (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activemodel (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + rails (6.1.7.4) + actioncable (= 6.1.7.4) + actionmailbox (= 6.1.7.4) + actionmailer (= 6.1.7.4) + actionpack (= 6.1.7.4) + actiontext (= 6.1.7.4) + actionview (= 6.1.7.4) + activejob (= 6.1.7.4) + activemodel (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) bundler (>= 1.15.0) - railties (= 6.1.7.3) + railties (= 6.1.7.4) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.1.7.4) + actionpack (= 6.1.7.4) + activesupport (= 6.1.7.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -423,10 +424,9 @@ GEM sshkit (1.21.4) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - staccato (0.5.3) - thor (1.2.1) + thor (1.2.2) tilt (2.1.0) - timeout (0.3.2) + timeout (0.4.0) trestle (0.9.8) activemodel (>= 4.2.0) kaminari (>= 1.1.0) @@ -455,7 +455,7 @@ GEM xpath (3.2.0) nokogiri (~> 1.8) yard (0.9.33) - zeitwerk (2.6.7) + zeitwerk (2.6.8) PLATFORMS arm64-darwin-21 @@ -509,7 +509,6 @@ DEPENDENCIES simplecov simplecov-lcov solargraph - staccato (~> 0.5.3) trestle (~> 0.9.5) trestle-search (~> 0.4.3) typhoeus (~> 1.4.0) diff --git a/server/app/controllers/concerns/analytics.rb b/server/app/controllers/concerns/analytics.rb index 72b649b9b..2f1528230 100644 --- a/server/app/controllers/concerns/analytics.rb +++ b/server/app/controllers/concerns/analytics.rb @@ -1,20 +1,5 @@ module Analytics extend ActiveSupport::Concern - included do - after_action :submit_analytics - end - - - def submit_analytics - if should_submit?(request) - SubmitApiAnalytics.perform_later( - path: request.path, - referrer: request.referer, - user_agent: request.user_agent, - user_ip: request.remote_ip, - ) - end - end def should_submit?(req) Rails.env.production? && req.headers['Civic-Client-Name'] != 'civic-frontend' diff --git a/server/app/controllers/links_controller.rb b/server/app/controllers/links_controller.rb index 5ec41e3fa..b0693c01e 100644 --- a/server/app/controllers/links_controller.rb +++ b/server/app/controllers/links_controller.rb @@ -1,6 +1,4 @@ class LinksController < ApplicationController - include Analytics - def redirect router = FrontendRouter.new( params[:idtype] || params[:idType], diff --git a/server/app/jobs/submit_api_analytics.rb b/server/app/jobs/submit_api_analytics.rb index da705d5bd..f0757ed67 100644 --- a/server/app/jobs/submit_api_analytics.rb +++ b/server/app/jobs/submit_api_analytics.rb @@ -1,6 +1,34 @@ +require 'uri' +require 'net/http' + class SubmitApiAnalytics < ApplicationJob + GA_MEASUREMENT_ID = 'G-Y6DR1YK7V9' + GA_API_SECRET = Rails.application.credentials.dig(:ga_api_secret) + + ANALYTICS_URL = "https://www.google-analytics.com/mp/collect?api_secret=#{GA_API_SECRET}&measurement_id=#{GA_MEASUREMENT_ID}" + HEADER = {'Content-Type': 'application/json'} + + def perform(opts = {}) - tracker = Staccato.tracker(Constants::GA_TRACKING_ID, nil, ssl: true) - tracker.pageview(opts) + Net::HTTP.post(URI(ANALYTICS_URL), create_body(body)) end + + private + def create_body(opts) + { + client_id: SecureRandom.uuid, + user_id: opts[:user_ip], + timestamp_micros: DateTime.now.strftime("%s%6N"), + events: [ + { + name: 'api_request', + params: { + query_type: opts[:query_type], + ip: opts[:user_ip] + } + } + ] + }.to_json + end + end diff --git a/server/app/lib/graphql_analytics_tracer.rb b/server/app/lib/graphql_analytics_tracer.rb index 5e1aefe99..2ba5311da 100644 --- a/server/app/lib/graphql_analytics_tracer.rb +++ b/server/app/lib/graphql_analytics_tracer.rb @@ -1,15 +1,12 @@ -RequestTracer = Struct.new(:path, :referrer, :user_agent, :user_ip, keyword_init: true) do +RequestTracer = Struct.new(:user_ip, keyword_init: true) do def trace(key, data) if key == "analyze_query" query = data[:query] - title = query.selected_operation.selections&.first&.name + query_type = query.selected_operation.selections&.first&.name SubmitApiAnalytics.perform_later( - path: path, - referrer: referrer, - user_agent: user_agent, user_ip: user_ip, - title: title + query_type: query_type ) end yield @@ -25,12 +22,7 @@ def self.trace(key, data) class GraphqlAnalyticsTracer def self.for_request(req) if Analytics.should_submit?(req) - RequestTracer.new( - path: req.path, - referrer: req.referrer, - user_agent: req.user_agent, - user_ip: req.remote_ip, - ) + RequestTracer.new(user_ip: req.remote_ip) else NullTracer end diff --git a/server/app/models/constants.rb b/server/app/models/constants.rb index ddb4cd260..3523a9f4b 100644 --- a/server/app/models/constants.rb +++ b/server/app/models/constants.rb @@ -10,8 +10,6 @@ module Constants DISPLAY_NAME_QUERY = 'users.username ILIKE :query OR users.email ILIKE :query OR users.name ILIKE :query' - GA_TRACKING_ID='UA-83153043-1' - EVIDENCE_TYPES = [:Diagnostic, :Prognostic, :Predictive, :Predisposing, :Functional, :Oncogenic] ASSERTION_TYPES = [:Diagnostic, :Prognostic, :Predictive, :Predisposing, :Oncogenic] diff --git a/server/config/credentials/development.yml.enc b/server/config/credentials/development.yml.enc index 0e7e3ef3c..8a2885c87 100644 --- a/server/config/credentials/development.yml.enc +++ b/server/config/credentials/development.yml.enc @@ -1 +1 @@ -LfdEQE4R3AaqJlhKHQD5lGSiyrDYUav1s6ef0dMlfCWYcCsSkrAb+qiadDHzkbla1a/fb3K3NbN2CW5zQSb+7/J/0Y0sNGuYKQNz0z7zU32Et4n5eZBMKH2zzp6IBo304M8ve/BygN+SWmnbj3k3WQnoR57XF+YqII5yEChP831RV28NBS+Y9uy4L3/zLh5OG33+e+Cqq8M=--XelBoSGJd6B0Wa0F--+wG2x4R2+SvoUXMcMpW2pw== \ No newline at end of file +YUBaxCAj7RVbpSez4OtMvyB2ZiigQ8Fkz+vrEYgbY3h7M2Xf8RrNa3ejOViWQk18ewlRLrA8ygOSvdH9dlImSRORlHB/Grp0Ysi8Ouq8tsbf5QP4xOxJqw/PmoWAdpFVolb409wX2oe39JieMKl4yJ04rtfo6vt6RHgFAF2eH+1mU4PK58I0GAvUxvZk9dfzP6OuqKbu38ftwR8var+CxDBkff7liEQAl/qaEwAhpJaAWudMkxpd8vRqmLwOOA==--bkcqg15bOAJK3wWT--uZOv8K+ey/iXj5JUwZowxg== \ No newline at end of file diff --git a/server/config/credentials/production.yml.enc b/server/config/credentials/production.yml.enc index 357786793..910a53d0a 100644 --- a/server/config/credentials/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tTxc/MVINHWgmdVlHm8JUFwdfViwFpiluAdhIk3y8WkDnY2h2Jgq0qRvo7sTT0y/RuO27sn2y5jQOlVKDqDW1y3Jv9JsfheUIdxgn127GYE+uRPDoyNUzzKmwGfQTrqs3EYg3CWe7lEJrTBrKDObYrLCwAdx2--LQHCfvpMC/eev8MC--vlWxDGJcIoQICo0sxfCNww== \ No newline at end of file diff --git a/server/lib/constants.rb b/server/lib/constants.rb deleted file mode 100644 index 493c116cb..000000000 --- a/server/lib/constants.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Constants - GA_TRACKING_ID='UA-83153043-1' -end