wideopenspaces-gstats 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 2
4
+ :major: 0
@@ -0,0 +1,61 @@
1
+ module GoogleStatsHelper
2
+ # google analytics helper
3
+ # the new GA code uses pageTrackers to set tracking information
4
+ def google_stats
5
+ add_tracker(:trackPageview, @analytics_url || nil)
6
+ add_tracker(:setDomainName, GStats.domain) if GStats.domain
7
+
8
+ google_js
9
+ end
10
+
11
+ # Use to set a cookie identifying the user as a specific segment of visitors, ie
12
+ # set_visitor_segment("member") or set_visitor_segment("non-member")
13
+ #
14
+ # Setting this overwrites any previous user segmentation cookie.
15
+ def set_visitor_segment(segment)
16
+ add_tracker(:setVar, segment)
17
+ end
18
+
19
+ # To set a 'virtual url' for a page , include
20
+ # <% analytics_url('/flower') %>
21
+ # somewhere in your view. It will appear in GA as the 'virtual url' instead of the real one.
22
+ def analytics_url(url)
23
+ @analytics_url = url
24
+ end
25
+
26
+ # Add a tracker to the Google Analytics script. Consult the Google Analytics API docs before randomly adding a tracker :)
27
+ # add_tracker can be invoked from anywhere prior to the output of the stats code
28
+ def add_tracker(tracker, value=nil)
29
+ @trackers ||= {}
30
+ @trackers[tracker] = value
31
+ end
32
+
33
+ #:nodoc:
34
+ def get_trackers
35
+ pt = @trackers.collect do |tracker, value|
36
+ value ? value = %!"#{value}"! : value = "" # if value, add quotes; if nil, make a blank string.
37
+ "pageTracker._#{tracker.to_s}(#{value});"
38
+ end
39
+ return pt.join(" ")
40
+ end
41
+ private :get_trackers
42
+
43
+ #:nodoc:
44
+ def google_js
45
+ trackers = <<-EOT
46
+ <!-- Start Google Analytics tag -->
47
+ <script type="text/javascript">
48
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
49
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
50
+ </script>
51
+ <script type="text/javascript">
52
+ try {
53
+ var pageTracker = _gat._getTracker("#{GStats.analytics_account}");
54
+ pageTracker._initData();
55
+ #{get_trackers}
56
+ } catch(err) {}</script>
57
+ <!-- End Google Analytics tag -->
58
+ EOT
59
+ end
60
+ private :google_js
61
+ end
data/lib/gstats.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'google_stats_helper'
2
+ module GStats
3
+ class << self
4
+ # Your analytics account code (usually starts with UA-)
5
+ attr_accessor :analytics_account
6
+
7
+ # Canonical domain name
8
+ attr_accessor :domain
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GstatsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'gstats'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wideopenspaces-gstats
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Jacob Stetser
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2009-01-22 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Helper for Google Analytics!
22
+ email: jake@wideopenspac.es
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - VERSION.yml
31
+ - lib/google_stats_helper.rb
32
+ - lib/gstats.rb
33
+ - test/gstats_test.rb
34
+ - test/test_helper.rb
35
+ homepage: http://github.com/wideopenspaces/gstats
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --inline-source
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.7.2
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Helper for Google Analytics!
69
+ test_files: []
70
+