Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial goal implementation

  • Loading branch information...
commit d942da3c5636daa9a42ea1c46ec8af939afbe537 1 parent fd31be8
@tpitale tpitale authored
View
1  lib/garb.rb
@@ -12,6 +12,7 @@
require 'garb/account_feed_request'
require 'garb/session'
require 'garb/profile_reports'
+require 'garb/goal'
require 'garb/profile'
require 'garb/account'
require 'garb/filter_parameters'
View
2  lib/garb/account_feed_request.rb
@@ -19,7 +19,7 @@ def entries
end
def segments
- parsed_response ? [parsed_response['dxp:segment']].flatten : []
+ parsed_response ? [parsed_response['feed']['dxp:segment']].flatten : []
end
end
end
View
18 lib/garb/goal.rb
@@ -0,0 +1,18 @@
+module Garb
+ class Goal
+ attr_reader :name, :number, :value
+
+ def initialize(attributes={})
+ return unless attributes.is_a?(Hash)
+
+ @name = attributes['name']
+ @number = attributes['number'].to_i
+ @value = attributes['value'].to_f
+ @active = (attributes['active'] == 'true')
+ end
+
+ def active?
+ @active
+ end
+ end
+end
View
3  lib/garb/profile.rb
@@ -3,12 +3,13 @@ class Profile
include ProfileReports
- attr_reader :session, :table_id, :title, :account_name, :account_id, :web_property_id, :segments
+ attr_reader :session, :table_id, :title, :account_name, :account_id, :web_property_id, :goals
def initialize(entry, session)
@session = session
@title = entry['title']
@table_id = entry['dxp:tableId']
+ @goals = (entry[Garb.to_ga('goal')] || []).map {|g| Goal.new(g)}
entry['dxp:property'].each do |p|
instance_variable_set :"@#{Garb.from_ga(p['name'])}", p['value']
View
14 test/fixtures/profile_feed.xml
@@ -26,6 +26,20 @@
<updated>2008-07-21T14:05:57.000-07:00</updated>
<title>Historical</title>
<link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+ <ga:goal active='true' name='Read Blog' number='1' value='10.0'>
+ <ga:destination caseSensitive='false' expression='/blog.html' matchType='head' step1Required='false'/>
+ </ga:goal>
+ <ga:goal active='true' name='Go for Support' number='2' value='5.0'>
+ <ga:destination caseSensitive='false' expression='/support.html' matchType='head' step1Required='false'/>
+ </ga:goal>
+ <ga:goal active='true' name='Contact Form Submission' number='3' value='100.0'>
+ <ga:destination caseSensitive='false' expression='/contact-submit' matchType='exact' step1Required='true'>
+ <ga:step name='Contact Form Page' number='1' path='/contact.html'/>
+ </ga:destination>
+ </ga:goal>
+ <ga:goal active='true' name='Newsletter Form Submission' number='4' value='25.0'>
+ <ga:destination caseSensitive='false' expression='/newsletter-submit' matchType='exact' step1Required='false'/>
+ </ga:goal>
<dxp:property name="ga:accountId" value="1111"/>
<dxp:property name="ga:accountName" value="Blog Beta"/>
<dxp:property name="ga:profileId" value="1212"/>
View
24 test/unit/garb/goal_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+
+module Garb
+ class GoalTest < MiniTest::Unit::TestCase
+ context "A Goal" do
+ should "have a name, number, and value" do
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
+ assert_equal 'Read Blog', goal.name
+ assert_equal 1, goal.number
+ assert_equal 10.0, goal.value
+ end
+
+ should "know if it is active" do
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'true'})
+ assert goal.active?
+ end
+
+ should "know if it is not active" do
+ goal = Goal.new({'name' => 'Read Blog', 'number' => '1', 'value' => '10.0', 'active' => 'false'})
+ assert_equal false, goal.active?
+ end
+ end
+ end
+end
View
6 test/unit/garb/profile_test.rb
@@ -40,7 +40,7 @@ class ProfileTest < MiniTest::Unit::TestCase
end
end
- context "An instance of the Profile class" do
+ context "A Profile" do
setup do
afr = AccountFeedRequest.new
afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
@@ -68,6 +68,10 @@ class ProfileTest < MiniTest::Unit::TestCase
should "have a value for :account_name" do
assert_equal 'Blog Beta', @profile.account_name
end
+
+ should "have goals" do
+ assert_equal 4, @profile.goals.size
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.