Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def apply_template!
setup_adrs # Put last for correct ordering in README
setup_semantic_logger

setup_dfe_analytics

fix_ci
fix_setup
bundle_with_checksums
Expand Down Expand Up @@ -157,6 +159,12 @@ def setup_semantic_logger
apply 'templates/semantic_logger.rb'
end

def setup_dfe_analytics
say("\n=== DfE Analytics ===")

apply 'templates/dfe_analytics.rb'
end

def fix_ci
say "\n=== Fixing CI configuration ==="
gsub_file("config/ci.rb", "yarn audit", "yarn npm audit")
Expand Down
45 changes: 45 additions & 0 deletions templates/dfe_analytics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
gem 'dfe-analytics', github: 'DFE-Digital/dfe-analytics', tag: 'v1.15.8'

bundle_command("install --quiet")

run "rails generate dfe:analytics:install"

airbyte_config = <<-RUBY
# Set a config file for Airbyte
config.airbyte_stream_config_path = 'config/analytics_airbyte_stream_config.json'
RUBY
# FIXME: Uncomment this whent he version is updated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# FIXME: Uncomment this whent he version is updated
# FIXME: Uncomment this when the version is updated

# insert_into_file("config/initializers/dfe_analytics.rb", airbyte_config, after: "DfE::Analytics.configure do |config|\n" )

azure_federated_auth_config = <<-RUBY
# FIXME: Review this setting to ensure it's appropriate for your application
# Use Azure Federated Auth [see docs](https://github.com/DFE-Digital/dfe-analytics?tab=readme-ov-file#31-workload-identity-federation)
config.azure_federated_auth = true
RUBY
gsub_file("config/initializers/dfe_analytics.rb", " # config.azure_federated_auth = false", azure_federated_auth_config)

log_only_config = <<-RUBY
# FIXME: Review this setting to ensure it's appropriate for your application
config.log_only = Rails.env.local?
RUBY
gsub_file("config/initializers/dfe_analytics.rb", " # config.log_only = true", log_only_config)

async_config = <<-RUBY
# FIXME: Review this setting to ensure it's appropriate for your application
config.async = !Rails.env.local?
RUBY
gsub_file("config/initializers/dfe_analytics.rb", " # config.async = true", async_config)

queue_config = <<-RUBY
config.queue = :dfe_analytics
RUBY
gsub_file("config/initializers/dfe_analytics.rb", " # config.queue = :default", queue_config)

inject_into_file(
"app/controllers/application_controller.rb",
"include DfE::Analytics::Requests\n".indent(2),
after: "class ApplicationController < ActionController::Base\n"
)