[deploy] Add ga tracking to config (#10150)
* Add ga tracking to config * Remove empty line * Remove console.log * Fix typo * Update app/assets/javascripts/initializers/initializeBaseTracking.js.erb * Add google tracking id example
This commit is contained in:
parent
27faf0a667
commit
b3f1e53ec7
10 changed files with 21 additions and 20 deletions
|
|
@ -34,7 +34,7 @@ module Admin
|
|||
|
||||
def config_params
|
||||
allowed_params = %i[
|
||||
ga_view_id
|
||||
ga_tracking_id
|
||||
periodic_email_digest_max
|
||||
periodic_email_digest_min
|
||||
sidebar_tags
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class GaEventsController < ApplicationController
|
|||
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(ApplicationConfig["GA_TRACKING_ID"], client_id)
|
||||
tracker = Staccato.tracker(SiteConfig.ga_tracking_id, client_id)
|
||||
tracker.pageview(
|
||||
path: json["path"],
|
||||
user_id: user_id,
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ module Constants
|
|||
description: "The \"Client Secret\" portion of the GitHub Oauth Apps portal",
|
||||
placeholder: ""
|
||||
},
|
||||
ga_view_id: {
|
||||
description: "Google Analytics Reporting API v4 - View ID",
|
||||
ga_tracking_id: {
|
||||
description: "Google Analytics Tracking ID, e.g. UA-71991000-1",
|
||||
placeholder: ""
|
||||
},
|
||||
health_check_token: {
|
||||
|
|
|
|||
|
|
@ -61,9 +61,8 @@ class SiteConfig < RailsSettings::Base
|
|||
field :jobs_url, type: :string
|
||||
field :display_jobs_banner, type: :boolean, default: false
|
||||
|
||||
# Google Analytics Reporting API v4
|
||||
# <https://developers.google.com/analytics/devguides/reporting/core/v4>
|
||||
field :ga_view_id, type: :string, default: ""
|
||||
# Google Analytics Tracking ID, e.g. UA-71991000-1
|
||||
field :ga_tracking_id, type: :string, default: ApplicationConfig["GA_TRACKING_ID"]
|
||||
|
||||
# Images
|
||||
field :main_social_image, type: :string
|
||||
|
|
|
|||
|
|
@ -464,11 +464,11 @@
|
|||
} %>
|
||||
<div id="gaBodyContainer" class="card-body collapse hide" aria-labelledby="gaBodyContainer">
|
||||
<div class="form-group">
|
||||
<%= admin_config_label :ga_view_id, "View ID" %>
|
||||
<%= f.text_field :ga_view_id,
|
||||
<%= admin_config_label :ga_tracking_id, "View ID" %>
|
||||
<%= f.text_field :ga_tracking_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.ga_view_id %>
|
||||
<div class="alert alert-info"><%= Constants::SiteConfig::DETAILS[:ga_view_id][:description] %></div>
|
||||
value: SiteConfig.ga_tracking_id %>
|
||||
<div class="alert alert-info"><%= Constants::SiteConfig::DETAILS[:ga_tracking_id][:description] %></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@
|
|||
m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
||||
|
||||
ga('create', '<%= ApplicationConfig["GA_TRACKING_ID"] %>', 'auto');
|
||||
ga('create', '<%= SiteConfig.ga_tracking_id %>', 'auto');
|
||||
ga('set', 'anonymizeIp', true);
|
||||
ga('send', 'pageview');
|
||||
ga('send', 'event', 'view', '/badge version impression', '<%= @html_variant.name %>', null);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@
|
|||
data-user-status="<%= user_logged_in_status %>"
|
||||
class="<%= SiteConfig.default_font.tr("_", "-") %>-article-body"
|
||||
data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>"
|
||||
data-app-name="<%= ApplicationConfig["APP_NAME"] %>">
|
||||
data-app-name="<%= ApplicationConfig["APP_NAME"] %>"
|
||||
data-ga-tracking="<%= SiteConfig.ga_tracking_id %>">
|
||||
<div id="body-styles">
|
||||
<style>
|
||||
:root {
|
||||
|
|
|
|||
|
|
@ -102,10 +102,6 @@ FASTLY_SERVICE_ID: ""
|
|||
# (https://www.honeycomb.io/)
|
||||
HONEYCOMB_API_KEY: ""
|
||||
|
||||
# Google analytic
|
||||
# (https://developers.google.com/analytics/devguides/reporting/core/v4)
|
||||
GA_TRACKING_ID: "Optional"
|
||||
|
||||
# Mailchimp for mails
|
||||
# (https://mailchimp.com/developer/)
|
||||
MAILCHIMP_API_KEY: "Optional-valid"
|
||||
|
|
|
|||
|
|
@ -175,9 +175,9 @@ RSpec.describe "/admin/config", type: :request do
|
|||
end
|
||||
|
||||
describe "Google Analytics Reporting API v4" do
|
||||
it "updates ga_view_id" do
|
||||
post "/admin/config", params: { site_config: { ga_view_id: "abc" }, confirmation: confirmation_message }
|
||||
expect(SiteConfig.ga_view_id).to eq("abc")
|
||||
it "updates ga_tracking_id" do
|
||||
post "/admin/config", params: { site_config: { ga_tracking_id: "abc" }, confirmation: confirmation_message }
|
||||
expect(SiteConfig.ga_tracking_id).to eq("abc")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ RSpec.describe "StoriesIndex", type: :request do
|
|||
expect(response.body).to include(CGI.escapeHTML(article.title))
|
||||
end
|
||||
|
||||
it "has data-ga-tracking" do
|
||||
get "/"
|
||||
expect(response.body).to include("data-ga-tracking=\"#{SiteConfig.ga_tracking_id}\"")
|
||||
end
|
||||
|
||||
it "renders registration page if site config is private" do
|
||||
SiteConfig.public = false
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue