* added organization policy + spec * user specs for is_org_admin? * added authroize to organization controller * admin policy + specs * deleted enforce admin due to pundit policy redundancy * applied admin policy to entire admin namespace * refactoring analytics controller WIP - wanna test codeship * Add protection against reactions to unpublished articles (#473) * Add chat channel policy and spec (#474) * Add comment policy and specs (#475) * Fix edge case with apostrophes * Add comment policy and specs * Add login for deleting comment spec * Change test to raise pundit error instead of 404 * Clean up comment destroy request specs * Remove redundant raise * Whitelist columns on to_json call (#477) * Add pundit policy for several controllers (#476) * Add pundit policy for several controllers * Adjust video spec * Fix tag request specs * Add proper twilio tokens request specs * Remove puts statements * Add a couple basic request specs (#478) * Add a few tests and fix user tag color bug (#482) * Refactor handle_tag_index in stories_controller (#481) * Modify valid_request_origin? (#483) * Add misc specs and remove banned attribute from user model (#484) * Fix missing Cloudinary tags and misc specs (#486) * removing current_user_is_admin? to use .is_admin? method * added missing org policy routes * Add comment for all public controllers * Fix edge case for test * Authorize mod controller and add specs * Refactor methods via inheritance and use only super_admin role * Create policy method for analytics via article_policy and refactor * Capitalize all buttons in dashboard page * Fix org tests and remove old admin test * Use only happy path for analytics * Fix tests to use Pundit error * Update org_policy spec
40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
class GaEventsController < ApplicationController
|
|
# No authorization required for entirely public controller
|
|
|
|
# This controller is for tracking activity when GA script fails
|
|
# IP is scrambled as to not be persisted to limit fingerprinting abilities on our end.
|
|
|
|
def create
|
|
json = JSON.parse(request.raw_post)
|
|
user_id = user_signed_in? ? current_user.id : nil
|
|
client_id = "#{scrambled_ip[0..12]}_#{json['user_agent']}_#{user_id}"
|
|
tracker = Staccato.tracker(ENV["GA_TRACKING_ID"], client_id)
|
|
tracker.pageview(
|
|
path: json["path"],
|
|
user_id: user_id,
|
|
user_language: json["user_language"],
|
|
referrer: (json["referrer"] if json["referrer"] && !json["referrer"].start_with?("https://dev.to")),
|
|
user_agent: json["user_agent"],
|
|
viewport_size: json["viewport_size"],
|
|
screen_resolution: json["screen_resolution"],
|
|
document_title: json["document_title"],
|
|
document_encoding: json["document_encoding"],
|
|
document_path: json["document_path"],
|
|
cache_buster: rand(100000000000).to_s,
|
|
data_source: "web",
|
|
)
|
|
logger.info("Server-Side Google Analytics Tracking - #{client_id}")
|
|
render body: nil
|
|
end
|
|
|
|
def scrambled_ip
|
|
crypt = ActiveSupport::MessageEncryptor.new(todays_key)
|
|
crypt.encrypt_and_sign(request.env["HTTP_X_FORWARDED_FOR"] || request.remote_ip)
|
|
end
|
|
|
|
def todays_key
|
|
Rails.cache.fetch("daily_random_key", expires_in: 48.hours) do
|
|
SecureRandom.random_bytes(32)
|
|
end
|
|
end
|
|
end
|