No commit activity in last 3 years
No release in over 3 years
middleman-google-analytics is a Middleman extension that generates Google Analytics tracking code, and keeps your config in config.rb, where it belongs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 5.1, >= 4.1
>= 0
< 4.0, >= 2.5
 Project Readme

middleman-google-analytics

Gem Version Build Status Dependency Status Coverage Status

middleman-google-analytics is a Middleman extension that generates Google Analytics tracking code, and keeps your config in config.rb, where it belongs.

Installation

  1. Specify the dependency in your project's Gemfile:
gem 'middleman-google-analytics', '~> 3.0'
  1. Activate the Google Analytics extension in your project's config.rb:
# config.rb
activate :google_analytics do |ga|
  ga.tracking_id = 'UA-XXXXXXX-X' # Replace with your property ID.
end
  1. In your layout, after your footer, call google_analytics_tag and include the results in the page:

Haml:

= google_analytics_tag

ERB:

<%= google_analytics_tag %>

JavaScript with ERB (js.erb):

<%= google_analytics_tag %>

Configuration

activate :google_analytics do |ga|
  # Property ID (default = nil)
  ga.tracking_id = 'UA-XXXXXXX-X'

  # Removing the last octet of the IP address (default = false)
  ga.anonymize_ip = false

  # Tracking across a domain and its subdomains (default = nil)
  ga.domain_name = 'example.com'

  # Tracking across multiple domains and subdomains (default = false)
  ga.allow_linker = false

  # Enhanced Link Attribution (default = false)
  ga.enhanced_link_attribution = false

  # Container ID for Google Optimize (A/B Testing)
  ga.optimize = 'GTM-123456'

  # Log detail messages to the console (default = false)
  ga.debug = false

  # Trace debugging will output more verbose information to the console (default = false)
  ga.debug_trace = false

  # Disable extension (default = false)
  ga.disable = true

  # Testing your implementation without sending hits (default = true) in development
  ga.test = true

  # Compress the JavaScript code (default = false)
  ga.minify = false

  # Output style - :html includes <script> tag (default = :html)
  ga.output = :js

end

Usage

Once you've bundled you should be able to run middleman as normal, and have it display the GA tracking code.

Special Thanks

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Copyright (c) 2014-present Daniel Bayerlein. See LICENSE for details.

Copyright (c) 2013 Jon Frisby.