Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin - How to add custom script before </body> tag?

I would like to do some analytics on my active admin enabled rails application. For that, I need to paste some <script> and <noscript> code just before the </body> tag in my layout file. Unfortunately, I am not able to do that as the application.html layout file seems ineffective since ActiveAdmin renders its own layout files.

Is there a hook/place where I can insert the custom html code ?

like image 874
bragboy Avatar asked Feb 17 '13 21:02

bragboy


1 Answers

Tested with ActiveAdmin 0.6.0 and Rails 4.0.5.

You can also override the arbre view used by active admin to render the footer. In your active_admin initializer add:

# config/initializers/active_admin.rb
require 'admin/analytics_footer'

ActiveAdmin.setup do |config|
  config.namespace :admin do |admin|
    config.view_factory.footer = Admin::AnalyticsFooter
  end
end

And define the view:

# lib/admin/analytics_footer.rb
module Admin
  class AnalyticsFooter < ActiveAdmin::Views::Footer
    def build
      super
      render('layouts/analytics')
    end
   end
 end

And place your ga tracking code in app/views/layouts/_analytics.html.erb. After a server restart the snippet should appear inside the footer at the end of the page.

like image 179
tfischbach Avatar answered Sep 23 '22 00:09

tfischbach