class GoogleAnalytics

Constants

ANONYMIZE_IP_CODE
ID_RE
INITIALIZE_CODE
PAGEVIEW_CODE
SETUP_CODE

source: developers.google.com/analytics/devguides/collection/analyticsjs/

Public Class Methods

new(config) click to toggle source
# File lib/analytics/GoogleAnalytics.rb, line 23
def initialize(config)
     if !(ID_RE.match(config["id"]))
         raise ArgumentError, 'Invalid Google analytics key. Id must look like UA-XXXXXX-Y'
     end

     @commands = []
     @commands.push(INITIALIZE_CODE % config["id"])
     @commands.push(PAGEVIEW_CODE)
     _get_other_commands(config)
 end

Public Instance Methods

render() click to toggle source
# File lib/analytics/GoogleAnalytics.rb, line 34
def render()
    return SETUP_CODE % @commands.join("\n\t")
end

Private Instance Methods

_get_other_commands(config) click to toggle source
# File lib/analytics/GoogleAnalytics.rb, line 40
def _get_other_commands(config)
    @commands.push(ANONYMIZE_IP_CODE % config.fetch(:anonymizeIp, false))
end