Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

Commit

Permalink
google universal
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilski81 committed Feb 4, 2014
1 parent 7ecf8ad commit 531183b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/analytical/modules/google_universal.rb
Expand Up @@ -27,6 +27,12 @@ def init_javascript(location)
end
end

def event(name, *args)
data = args.first || {}
data = data[:value] if data.is_a?(Hash)
data_string = !data.nil? ? ", #{data}" : ""
"ga('send', 'event', 'Event', '#{name}' #{data_string});"
end
end
end
end
35 changes: 35 additions & 0 deletions spec/analytical/modules/google_universal_spec.rb
@@ -0,0 +1,35 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe "Analytical::Modules::GoogleUniveresal" do
before(:each) do
@parent = mock('api', :options=>{:google=>{:key=>'abc'}})
end
describe "on initialize" do
it "should set the command_location" do
a = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abc'
a.tracking_command_location.should == :head_append
end
it 'should set the options' do
a = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abc'
a.options.should == {:key=>'abc', :parent=>@parent}
end
end
describe '#event' do
it 'should return the event javascript' do
@api = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abcdef'
@api.event('pagename').should == "ga('send', 'event', 'Event', 'pagename' );"
end
it 'should include data value' do
@api = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abcdef'
@api.event('pagename', {:value=>555, :more=>'info'}).should == "ga('send', 'event', 'Event', 'pagename' , 555);"
end
it 'should not include data if there is no value' do
@api = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abcdef'
@api.event('pagename', {:more=>'info'}).should == "ga('send', 'event', 'Event', 'pagename' );"
end
it 'should not include data if it is not a hash' do
@api = Analytical::Modules::GoogleUniversal.new :parent=>@parent, :key=>'abcdef'
@api.event('pagename', 555).should == "ga('send', 'event', 'Event', 'pagename' , 555);"
end
end
end

0 comments on commit 531183b

Please sign in to comment.