Browse files

Initial commit

  • Loading branch information...
0 parents commit 25d9becdb4df8382e9f6fdf664302f933da6c3a8 @deadprogram deadprogram committed Nov 27, 2010
Showing with 139 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +6 −0 Gemfile
  3. +16 −0 Gemfile.lock
  4. +1 −0 README
  5. +8 −0 Rakefile
  6. +21 −0 gabba.gemspec
  7. +62 −0 lib/gabba.rb
  8. +3 −0 lib/gabba/version.rb
  9. +14 −0 spec/gabba_spec.rb
  10. +5 −0 spec/spec_helper.rb
3 .gitignore
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
6 Gemfile
@@ -0,0 +1,6 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in gabba.gemspec
+gemspec
+
+gem 'minitest'
16 Gemfile.lock
@@ -0,0 +1,16 @@
+PATH
+ remote: .
+ specs:
+ gabba (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ minitest (2.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ gabba!
+ minitest
1 README
@@ -0,0 +1 @@
+Simple class to send custom events to Google Analytics
8 Rakefile
@@ -0,0 +1,8 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+task :default => :spec
+
+task :spec do
+ ruby "spec/gabba_spec.rb"
+end
21 gabba.gemspec
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "gabba/version"
+
+Gem::Specification.new do |s|
+ s.name = "gabba"
+ s.version = Gabba::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["TODO: Write your name"]
+ s.email = ["TODO: Write your email address"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "gabba"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
62 lib/gabba.rb
@@ -0,0 +1,62 @@
+# yo, easy server-side tracking for Google Analytics... hey!
+module Gabba
+ class Gabba
+ BEACON_URL = "http://www.google-analytics.com/__utm.gif"
+ TRACKING_URL = "http://www.google-analytics.com/ga.js"
+
+ attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc
+
+
+# private $defaultAnalyticsType = "event";
+
+# private static $trackingDomain = "www.example.com"; // Your host
+
+# private $utmt; // Analytics type (event)
+# private $utmcc; //Cookie related variables
+
+ def initialiaze(domain, ga_acct)
+ @utmwv = "4.3" # GA version
+ @utmcs = "UTF-8" # charset
+ @utmul = "en-us" # language
+
+ @utmn = rand(1000000000..9999999999).to_s
+ @utmhid = rand(1000000000..9999999999).to_s
+
+ @utmhn = domain
+ @utmac = ga_acct
+ end
+
+ def page_view(title, page, utmhid = rand(1000000000..9999999999).to_s)
+ "utmwv=#{@utmwv}&utmn=#{@utmn}&utmhn=#{@utmhn}&utmcs=#{@utmcs}&utmul=#{@utmul}&utmdt=#{title}&utmhid=#{utmhid}&utmp=#{page}&utmac=#{@utmac}&utmcc=#{cookie_params}"
+ end
+
+ def event(category, action, label, value)
+
+ end
+
+ def cookie_params(today = Time.now)
+ "__utma=1.#{rand(10000000..99999999)}00145214523.#{rand(1000000000..2147483647)}.#{today}.#{today}.15;+__utmz=1.#{today}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);"
+ end
+
+
+
+ # def utm_gif_url(tracker = "tracker/serverevent", uservar = "-")
+ # url = "http://www.google-analytics.com/__utm.gif?utmwv=1"
+ # url += "&utmn=" + rand(1000000000..9999999999).to_s
+ # url += "&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-"
+ # url += "&utmhn=" + domain
+ #
+ # referer = request.env['HTTP_REFERER']
+ # referer = "-" if referer.blank?
+ # url += "&utmr=" + CGI.escape(referer)
+ #
+ # url += "&utmp=" + tracker
+ #
+ # url += "&utmac=" + ga_acct
+ #
+ # cookie = rand(10000000..99999999).to_s
+ # today = Time.new.getutc
+ # url += "&utmcc=__utma%3D=" + cookie + "." + rand(1000000000..2147483647).to_s + "." + today + "." + today + "." + today + ".2%3B%2B__utmb%3D" + cookie + "%3B%2B__utmc%3D" + cookie + "%3B%2B__utmz%3D" + cookie + "." + today + ".2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D" + cookie + "." + uservar + "%3B"
+ # end
+ end
+end
3 lib/gabba/version.rb
@@ -0,0 +1,3 @@
+module Gabba
+ VERSION = "0.0.1"
+end
14 spec/gabba_spec.rb
@@ -0,0 +1,14 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe Gabba::Gabba do
+ before do
+ @gabba = Gabba::Gabba.new
+ end
+
+ describe "yo" do
+ it "should respond positively" do
+ @gabba.must_equal "OHAI!"
+ end
+ end
+
+end
5 spec/spec_helper.rb
@@ -0,0 +1,5 @@
+require 'rubygems'
+gem 'minitest'
+require 'minitest/autorun'
+
+require File.dirname(__FILE__) + '/../lib/gabba'

0 comments on commit 25d9bec

Please sign in to comment.