Sha256: 3169cc370173f3a2d184f6e5fce05b22e54deaba56d3d64e96d27b2bb84bd3d7

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'alula/plugin'

module Alula
  class Analytics
    def self.path
      File.join(File.dirname(__FILE__), %w{.. .. .. plugins analytics})
    end
    
    def self.version
      Alula::Plugins::VERSION
    end
    
    def self.install(options)
      return false unless options.kind_of?(Hash)
      
      options.each do |provider, opts|
        tracker = case provider
        when "gosquared"
          <<-EOT
            <script type="text/javascript">var GoSquared={};GoSquared.acct="#{opts}",function(e){function t(){e._gstc_lt=+(new Date);var t=document,n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="//d1l6p2sc9645hc.cloudfront.net/tracker.js";var r=t.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)}e.addEventListener?e.addEventListener("load",t,!1):e.attachEvent("onload",t)}(window);</script>
            EOT
        when "woopra"
          <<-EOT
          <script type="text/javascript">function woopraReady(e){return e.setDomain("#{opts}"),e.setIdleTimeout(3e5),e.track(),!1}(function(){var e=document.createElement("script");e.src=document.location.protocol+"//static.woopra.com/js/woopra.js",e.type="text/javascript",e.async=!0;var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();</script>
          EOT
        end
        Alula::Plugin.addon(:body, ->(context) { tracker }) if tracker
      end
    end
  end
end

Alula::Plugin.register :analytics, Alula::Analytics

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alula-plugins-0.4.3 lib/alula/plugins/analytics.rb