2

I've followed these steps and I successfully see traffic going to my site, the problem is I can see the traffic of every controller/method EXCEPT those within the admin namespace, because the script at app/views/layouts/application.html.erb (the one shown below) is not executed at any ActiveAdmin page...

<script>
  (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-XXXXXXX-XX', 'herokuapp.com');
  ga('send', 'pageview');
</script>

I know Devise is able to tell me how many times an user have sign in my site, but I would like to see more statistics....

How could I solve this? I don't want put a render partial with that code in every ActiveAdmin's controller/method just for this task... is there an app/views/layouts/application.html.erb equivalent for ActiveAdmin? I mean a way to put a script tag in every ActiveAdmin's view?

Patricio Sard
  • 2,092
  • 3
  • 22
  • 52

1 Answers1

1

You can add custom scripts to ActiveAdmin's layout by simply editing app/assets/javascripts/active_admin.js. This file should have been created when you first set up ActiveAdmin.

Create a new javascript file to hold the Google Analytics script, and simply include the new script in active_admin.js.

It should look something like this:

// app/assets/javascripts/google_analytics.js

// Google analytics script goes here.
// app/assets/javascripts/active_admin.js 

//= require active_admin/base
//= require ./google_analytics
Hari Gopal
  • 718
  • 3
  • 7