Skip to content

Commit

Permalink
Merge pull request #556 from alphagov/add-basic-admin-analytics
Browse files Browse the repository at this point in the history
Add admin analytics component
  • Loading branch information
tijmenb committed Oct 2, 2018
2 parents f7c9ca9 + 930666c commit 5c06a62
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Add Admin analytics script (#555)
* You can now use `GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment` to get the current environment, for use in the admin layout components (PR #548)
* Update GOV.UK Frontend from 1.2.0 to 2.1.0 and manage breaking changes (PR #545)
* Add navigation and meta links to footer component (PR #550)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script class="analytics">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-26179049-6', '<%= ENV['GOVUK_APP_DOMAIN'] %>');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Admin Analytics
description: |
Google Analytics script for tracking user interaction in admin (backend) apps.
accessibility_criteria: |
The component should not be visible to any users.
display_html: true
examples:
default:
data: {}
13 changes: 13 additions & 0 deletions spec/components/admin_analytics_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

describe "Admin analytics", type: :view do
def component_name
"admin_analytics"
end

it "renders a script tag" do
render_component({})

assert_select "script"
end
end
4 changes: 2 additions & 2 deletions spec/components/all_components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it "has the correct class in the ERB template",
skip: component_name.in?(%w[step_by_step_nav_related step_by_step_nav_header step_by_step_nav previous_and_next_navigation]),
not_applicable: component_name.in?(%w[meta_tags machine_readable_metadata google_tag_manager_script layout_for_admin table]) do
not_applicable: component_name.in?(%w[meta_tags machine_readable_metadata google_tag_manager_script layout_for_admin table admin_analytics]) do

erb = File.read(filename)

Expand All @@ -38,7 +38,7 @@
expect(File).to exist(rspec_file)
end

it "has a correctly named SCSS file", not_applicable: component_name.in?(%w[contextual_breadcrumbs contextual_sidebar government_navigation machine_readable_metadata meta_tags google_tag_manager_script]) do
it "has a correctly named SCSS file", not_applicable: component_name.in?(%w[contextual_breadcrumbs admin_analytics contextual_sidebar government_navigation machine_readable_metadata meta_tags google_tag_manager_script]) do
css_file = "#{__dir__}/../../app/assets/stylesheets/govuk_publishing_components/components/_#{component_name.tr('_', '-')}.scss"

expect(File).to exist(css_file)
Expand Down

0 comments on commit 5c06a62

Please sign in to comment.