analytics_goo 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/analytics_goo.gemspec +28 -30
- data/lib/analytics_goo/google_analytics_adapter.rb +38 -11
- data/test/analytics_goo_test.rb +8 -2
- metadata +9 -10
- data/.gitignore +0 -7
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.1. | 
| 1 | 
            +
            0.1.4
         | 
    
        data/analytics_goo.gemspec
    CHANGED
    
    | @@ -1,49 +1,46 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 1 4 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 2 5 |  | 
| 3 6 | 
             
            Gem::Specification.new do |s|
         | 
| 4 7 | 
             
              s.name = %q{analytics_goo}
         | 
| 5 | 
            -
              s.version = "0.1. | 
| 8 | 
            +
              s.version = "0.1.4"
         | 
| 6 9 |  | 
| 7 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 8 11 | 
             
              s.authors = ["Rob Christie"]
         | 
| 9 | 
            -
              s.date = %q{2011- | 
| 12 | 
            +
              s.date = %q{2011-06-01}
         | 
| 10 13 | 
             
              s.email = %q{robchristie@gmail.com}
         | 
| 11 14 | 
             
              s.extra_rdoc_files = [
         | 
| 12 | 
            -
                "README.markdown"
         | 
| 15 | 
            +
                "README.markdown",
         | 
| 16 | 
            +
                "TODO"
         | 
| 13 17 | 
             
              ]
         | 
| 14 18 | 
             
              s.files = [
         | 
| 15 | 
            -
                " | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                 "test/analytics_goo_test.rb",
         | 
| 36 | 
            -
                 "test/test_helper.rb"
         | 
| 19 | 
            +
                "CHANGELOG",
         | 
| 20 | 
            +
                "MIT-LICENSE",
         | 
| 21 | 
            +
                "README.markdown",
         | 
| 22 | 
            +
                "Rakefile",
         | 
| 23 | 
            +
                "TODO",
         | 
| 24 | 
            +
                "VERSION",
         | 
| 25 | 
            +
                "analytics_goo.gemspec",
         | 
| 26 | 
            +
                "autotest/CHANGELOG",
         | 
| 27 | 
            +
                "autotest/LICENSE",
         | 
| 28 | 
            +
                "autotest/README.rdoc",
         | 
| 29 | 
            +
                "autotest/discover.rb",
         | 
| 30 | 
            +
                "autotest/railsplugin.rb",
         | 
| 31 | 
            +
                "autotest/railsplugin_rspec.rb",
         | 
| 32 | 
            +
                "init.rb",
         | 
| 33 | 
            +
                "lib/analytics_goo.rb",
         | 
| 34 | 
            +
                "lib/analytics_goo/google_analytics_adapter.rb",
         | 
| 35 | 
            +
                "rails/init.rb",
         | 
| 36 | 
            +
                "tasks/analytics_goo.rake",
         | 
| 37 | 
            +
                "test/analytics_goo_test.rb",
         | 
| 38 | 
            +
                "test/test_helper.rb"
         | 
| 37 39 | 
             
              ]
         | 
| 38 40 | 
             
              s.homepage = %q{http://github.com/eyestreet/analytics_goo}
         | 
| 39 | 
            -
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 40 41 | 
             
              s.require_paths = ["lib"]
         | 
| 41 42 | 
             
              s.rubygems_version = %q{1.3.6}
         | 
| 42 43 | 
             
              s.summary = %q{AnalyticsGoo provides server side non-javascript tracking using google analytics.}
         | 
| 43 | 
            -
              s.test_files = [
         | 
| 44 | 
            -
                "test/analytics_goo_test.rb",
         | 
| 45 | 
            -
                 "test/test_helper.rb"
         | 
| 46 | 
            -
              ]
         | 
| 47 44 |  | 
| 48 45 | 
             
              if s.respond_to? :specification_version then
         | 
| 49 46 | 
             
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| @@ -55,3 +52,4 @@ Gem::Specification.new do |s| | |
| 55 52 | 
             
              else
         | 
| 56 53 | 
             
              end
         | 
| 57 54 | 
             
            end
         | 
| 55 | 
            +
             | 
| @@ -40,9 +40,10 @@ | |
| 40 40 |  | 
| 41 41 | 
             
            module AnalyticsGoo
         | 
| 42 42 | 
             
              class GoogleAnalyticsAdapter
         | 
| 43 | 
            -
                attr_accessor :domain, :analytics_id, :env, :noop, :page_title, :remote_address, | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 43 | 
            +
                attr_accessor :domain, :analytics_id, :env, :noop, :page_title, :remote_address,
         | 
| 44 | 
            +
                              :referrer, :user_agent, :http_accept_language, :campaign, :source,
         | 
| 45 | 
            +
                              :medium, :term, :content
         | 
| 46 | 
            +
             | 
| 46 47 |  | 
| 47 48 | 
             
                def initialize(ac)
         | 
| 48 49 | 
             
                  # sets the environment that this should be run in
         | 
| @@ -55,6 +56,11 @@ module AnalyticsGoo | |
| 55 56 | 
             
                  @remote_address = ac[:remote_address]
         | 
| 56 57 | 
             
                  @user_agent = ac[:user_agent] || ""
         | 
| 57 58 | 
             
                  @http_accept_language = ac[:http_accept_language] || ""
         | 
| 59 | 
            +
                  @campaign =  ac[:campaign] || ""
         | 
| 60 | 
            +
                  @source = ac[:source] || ""
         | 
| 61 | 
            +
                  @medium = ac[:medium] || ""
         | 
| 62 | 
            +
                  @term = ac[:term] || ""
         | 
| 63 | 
            +
                  @content = ac[:content] || ""
         | 
| 58 64 | 
             
                end
         | 
| 59 65 |  | 
| 60 66 | 
             
                GA_DOMAIN = "www.google-analytics.com"
         | 
| @@ -134,11 +140,7 @@ module AnalyticsGoo | |
| 134 140 | 
             
                # utmip
         | 
| 135 141 | 
             
                # Remote IP address
         | 
| 136 142 | 
             
                def utmip
         | 
| 137 | 
            -
                   | 
| 138 | 
            -
                  # Capture the first three octects of the IP address and replace the forth
         | 
| 139 | 
            -
                  # with 0, e.g. 124.455.3.123 becomes 124.455.3.0
         | 
| 140 | 
            -
                  ip = self.remote_address.to_s.gsub!(/([^.]+\.[^.]+\.[^.]+\.)[^.]+/,"\\1") + "0"
         | 
| 141 | 
            -
                  ip
         | 
| 143 | 
            +
                  self.remote_address
         | 
| 142 144 | 
             
                end
         | 
| 143 145 |  | 
| 144 146 |  | 
| @@ -168,6 +170,27 @@ module AnalyticsGoo | |
| 168 170 | 
             
                  self.page_title
         | 
| 169 171 | 
             
                end
         | 
| 170 172 |  | 
| 173 | 
            +
                def utm_campaign
         | 
| 174 | 
            +
                  self.campaign
         | 
| 175 | 
            +
                end
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                def utm_source
         | 
| 178 | 
            +
                  self.source
         | 
| 179 | 
            +
                end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
             | 
| 182 | 
            +
                def utm_medium
         | 
| 183 | 
            +
                  self.medium
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                def utm_term
         | 
| 187 | 
            +
                  self.term
         | 
| 188 | 
            +
                end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                def utm_content
         | 
| 191 | 
            +
                  self.content
         | 
| 192 | 
            +
                end
         | 
| 193 | 
            +
             | 
| 171 194 | 
             
                # send a request to get the image from google
         | 
| 172 195 | 
             
                def track_page_view(path)
         | 
| 173 196 | 
             
                  res = ""
         | 
| @@ -179,7 +202,7 @@ module AnalyticsGoo | |
| 179 202 |  | 
| 180 203 | 
             
                protected
         | 
| 181 204 | 
             
                def track_it(path)
         | 
| 182 | 
            -
            # | 
| 205 | 
            +
                  #TODO - cleanup
         | 
| 183 206 | 
             
                  utm_uri = "/__utm.gif?" +
         | 
| 184 207 | 
             
                            "utmwv="  + self.utmwv +
         | 
| 185 208 | 
             
                            "&utmn="  + self.utmn +
         | 
| @@ -189,8 +212,12 @@ module AnalyticsGoo | |
| 189 212 | 
             
                            "&utmac=" + self.utmac +
         | 
| 190 213 | 
             
                            "&utmcc=" + self.utmcc +
         | 
| 191 214 | 
             
                            "&utmvid="+ self.utmvid +
         | 
| 192 | 
            -
                            "&utmip=" + self.utmip | 
| 193 | 
            -
             | 
| 215 | 
            +
                            "&utmip=" + self.utmip
         | 
| 216 | 
            +
                  utm_uri << "&utmdt=#{CGI.escape(self.utmdt)}"               unless self.utmdt.blank?
         | 
| 217 | 
            +
                  utm_uri << "&utm_campaign=#{CGI.escape(self.utm_campaign)}" unless self.utm_campaign.blank?
         | 
| 218 | 
            +
                  utm_uri << "&utm_source=#{CGI.escape(self.utm_source)}"     unless self.utm_source.blank?
         | 
| 219 | 
            +
                  utm_uri << "&utm_medium=#{CGI.escape(self.utm_medium)}"     unless self.utm_medium.blank?
         | 
| 220 | 
            +
                  utm_uri << "&utm_term=#{CGI.escape(self.utm_term)}"         unless self.utm_term.blank?
         | 
| 194 221 | 
             
                  Net::HTTP.start(GA_DOMAIN) {|http|
         | 
| 195 222 | 
             
                    http.request_get(utm_uri, {"User-Agent" => self.user_agent, "Accept-Language" => self.http_accept_language})
         | 
| 196 223 | 
             
                  }
         | 
    
        data/test/analytics_goo_test.rb
    CHANGED
    
    | @@ -34,7 +34,7 @@ class AnalyticsGooTest < ActiveSupport::TestCase | |
| 34 34 |  | 
| 35 35 | 
             
              context "AnalyticsGoo " do
         | 
| 36 36 | 
             
                setup do
         | 
| 37 | 
            -
                  @analytics_config = { :analytics_id => "MO-11685745-3",:domain => "test.local", :page_title => "This is the page title"}
         | 
| 37 | 
            +
                  @analytics_config = { :analytics_id => "MO-11685745-3",:domain => "test.local", :page_title => "This is the page title",  :remote_address => "127.0.0.1"}
         | 
| 38 38 | 
             
                  @ga = AnalyticsGoo::GoogleAnalyticsAdapter.new(@analytics_config)
         | 
| 39 39 | 
             
                end
         | 
| 40 40 | 
             
                context "when initialized with an analytics id" do
         | 
| @@ -47,6 +47,12 @@ class AnalyticsGooTest < ActiveSupport::TestCase | |
| 47 47 | 
             
                    assert_equal "test.local", @ga.domain
         | 
| 48 48 | 
             
                  end
         | 
| 49 49 | 
             
                end
         | 
| 50 | 
            +
                context "when initialized with a remote ip address" do
         | 
| 51 | 
            +
                  should "return that IP" do
         | 
| 52 | 
            +
                    assert_equal "127.0.0.1", @ga.utmip
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 50 56 | 
             
                context "that has been initialized" do
         | 
| 51 57 | 
             
                  should "have an urchin url" do
         | 
| 52 58 | 
             
                    assert_equal "http://www.google-analytics.com/__utm.gif", @ga.urchin_url
         | 
| @@ -137,7 +143,7 @@ class AnalyticsGooTest < ActiveSupport::TestCase | |
| 137 143 | 
             
                end
         | 
| 138 144 | 
             
                context "makes a request for an image on the google analytics server" do
         | 
| 139 145 | 
             
                  setup do
         | 
| 140 | 
            -
                    path = "/__utm.gif?utmwv=4.4sj&utmn=1277734430&utmhn=shor.tswit.ch&utmr=-&utmp=%2Fadmin%2F1&utmac=MO-11685745-3&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid=0x5719fb3b1e05e909&utmip=127.0.0. | 
| 146 | 
            +
                    path = "/__utm.gif?utmwv=4.4sj&utmn=1277734430&utmhn=shor.tswit.ch&utmr=-&utmp=%2Fadmin%2F1&utmac=MO-11685745-3&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid=0x5719fb3b1e05e909&utmip=127.0.0.1"
         | 
| 141 147 | 
             
                    header_hash =  {'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6', 'Accept-Language' => 'en-us,en;q=0.5'}
         | 
| 142 148 | 
             
                    @test_ad.expects(:utmn).returns("1277734430")
         | 
| 143 149 | 
             
                    @test_ad.expects(:utmvid).returns("0x5719fb3b1e05e909")
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: analytics_goo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 19
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 1
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.1. | 
| 9 | 
            +
              - 4
         | 
| 10 | 
            +
              version: 0.1.4
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Rob Christie
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011- | 
| 18 | 
            +
            date: 2011-06-01 00:00:00 -04:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: []
         | 
| 21 21 |  | 
| @@ -27,8 +27,8 @@ extensions: [] | |
| 27 27 |  | 
| 28 28 | 
             
            extra_rdoc_files: 
         | 
| 29 29 | 
             
            - README.markdown
         | 
| 30 | 
            +
            - TODO
         | 
| 30 31 | 
             
            files: 
         | 
| 31 | 
            -
            - .gitignore
         | 
| 32 32 | 
             
            - CHANGELOG
         | 
| 33 33 | 
             
            - MIT-LICENSE
         | 
| 34 34 | 
             
            - README.markdown
         | 
| @@ -54,8 +54,8 @@ homepage: http://github.com/eyestreet/analytics_goo | |
| 54 54 | 
             
            licenses: []
         | 
| 55 55 |  | 
| 56 56 | 
             
            post_install_message: 
         | 
| 57 | 
            -
            rdoc_options: 
         | 
| 58 | 
            -
             | 
| 57 | 
            +
            rdoc_options: []
         | 
| 58 | 
            +
             | 
| 59 59 | 
             
            require_paths: 
         | 
| 60 60 | 
             
            - lib
         | 
| 61 61 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| @@ -83,6 +83,5 @@ rubygems_version: 1.3.6 | |
| 83 83 | 
             
            signing_key: 
         | 
| 84 84 | 
             
            specification_version: 3
         | 
| 85 85 | 
             
            summary: AnalyticsGoo provides server side non-javascript tracking using google analytics.
         | 
| 86 | 
            -
            test_files: 
         | 
| 87 | 
            -
             | 
| 88 | 
            -
            - test/test_helper.rb
         | 
| 86 | 
            +
            test_files: []
         | 
| 87 | 
            +
             |