Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Jun 30, 2023
2 parents 20d2a48 + a57000d commit 15e9291
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 110 deletions.
3 changes: 0 additions & 3 deletions server/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down
137 changes: 68 additions & 69 deletions server/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions server/app/controllers/concerns/analytics.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 0 additions & 2 deletions server/app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class LinksController < ApplicationController
include Analytics

def redirect
router = FrontendRouter.new(
params[:idtype] || params[:idType],
Expand Down
32 changes: 30 additions & 2 deletions server/app/jobs/submit_api_analytics.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 4 additions & 12 deletions server/app/lib/graphql_analytics_tracer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions server/app/models/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion server/config/credentials/development.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LfdEQE4R3AaqJlhKHQD5lGSiyrDYUav1s6ef0dMlfCWYcCsSkrAb+qiadDHzkbla1a/fb3K3NbN2CW5zQSb+7/J/0Y0sNGuYKQNz0z7zU32Et4n5eZBMKH2zzp6IBo304M8ve/BygN+SWmnbj3k3WQnoR57XF+YqII5yEChP831RV28NBS+Y9uy4L3/zLh5OG33+e+Cqq8M=--XelBoSGJd6B0Wa0F--+wG2x4R2+SvoUXMcMpW2pw==
YUBaxCAj7RVbpSez4OtMvyB2ZiigQ8Fkz+vrEYgbY3h7M2Xf8RrNa3ejOViWQk18ewlRLrA8ygOSvdH9dlImSRORlHB/Grp0Ysi8Ouq8tsbf5QP4xOxJqw/PmoWAdpFVolb409wX2oe39JieMKl4yJ04rtfo6vt6RHgFAF2eH+1mU4PK58I0GAvUxvZk9dfzP6OuqKbu38ftwR8var+CxDBkff7liEQAl/qaEwAhpJaAWudMkxpd8vRqmLwOOA==--bkcqg15bOAJK3wWT--uZOv8K+ey/iXj5JUwZowxg==
2 changes: 1 addition & 1 deletion server/config/credentials/production.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ZhJ6XOxZWH3TwCybY1Tb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5jQOlVKDqDW1y3Jv9JsfheUIdxgn127GYE+uRPDoyNUzzKmwGfQTrqs3EYg3CWe7lEJrTBrKDObYrLCwAdx2--LQHCfvpMC/eev8MC--vlWxDGJcIoQICo0sxfCNww==
3 changes: 0 additions & 3 deletions server/lib/constants.rb

This file was deleted.

0 comments on commit 15e9291

Please sign in to comment.