Skip to content

Commit

Permalink
Piwik: added settings.yml integration
Browse files Browse the repository at this point in the history
Rationale:

 * In production mode, analytics MUST be configured, via the following
   in your config/settings.yml:

     :piwik:
       :url: "https://backup1.panmind.org/piwik"
       🆔  1

   If you *really* want to disable analytics in production mode, there's
   a specialized setting for that:

     :piwik:
       :i_really_want_to_disable_analytics: true

   Useful on pmdev.* and on developer working copies running in production
   mode for testing purposes.

 * In development mode, analytics tags aren't generated, so no config
   is needed.

 * In test mode, a dumb "test.host/piwik" configuration is generated
   automatically.

The settings.yml.sample file has been updated with relevant settings.
  • Loading branch information
vjt committed Jul 18, 2010
1 parent 28ef7f3 commit e39f249
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions lib/pm/piwik.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
module PM
module Piwik
def piwik_base
#request.protocol + 'backup1.panmind.org/piwik/'
'https://backup1.panmind.org/piwik/'
if Rails.env.production?
Config = APPLICATION_CONFIG[:piwik]

# *Enforce* analytics configuration in production mode
#
# If you're developing and want to run your local copy
# in production mode, you can either add dumb settings
# in your settings.yml, to check how the Piwik JS code
# is being generated:
#
# :piwik:
# :url: http://localhost/piwik
# :id: 31337
#
# Or, if you're really not interested at all in any of
# the Piwik bells and whistles, you can boldly disable
# it via the following configuration:
#
# :piwik:
# :i_really_want_to_disable_analytics: true
#
raise ArgumentError, 'Analytics configuration missing' if Config.blank?
elsif Rails.env.test?
Config = {:url => 'http://test.host/piwik', :id => 420}
end

def piwik_url
#request.protocol + APPLICATION_CONFIG[:piwik][:path]
Config[:url]
end

def piwik_id
1
Config[:id]
end

def piwik_js
piwik_base + 'piwik.js'
piwik_url + '/piwik.js'
end

def piwik_php
piwik_base + 'piwik.php'
piwik_url + '/piwik.php'
end

def piwik_disabled?
Rails.env.development? || Config[:i_really_want_to_disable_analytics]
end

Piwik = ''
def piwik_analytics_tags
return if piwik_disabled?

if Piwik.blank?
Piwik.replace(
javascript_include_tag(piwik_js) +
Expand Down

0 comments on commit e39f249

Please sign in to comment.