server_side_ga 0.0.1
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/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/lib/server_side_ga.rb +68 -0
- data/lib/server_side_ga/version.rb +3 -0
- data/server_side_ga.gemspec +25 -0
- metadata +100 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 James Kennedy
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# ServerSideGa
|
|
2
|
+
|
|
3
|
+
A wrapper allowing you to post events to the Google Universal Analytics Server side API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'server_side_ga'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install server_side_ga
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Once installed you can call events and transactions.
|
|
22
|
+
|
|
23
|
+
Eg:
|
|
24
|
+
ServerSideGa.event(tracking_code, client_id, category, action, label = nil, value = nil )
|
|
25
|
+
ServerSideGa.transaction( tracking_code, client_id, id, name, revenue, shipping = 0, tax = 0, currency = "USD", time = Time.now)
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
|
|
29
|
+
1. Fork it
|
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require "server_side_ga/version"
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module ServerSideGa
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@@endpoint = "http://www.google-analytics.com/collect"
|
|
10
|
+
@@version = "1"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def self.event(tracking_code, client_id, category, action, label = nil, value = nil )
|
|
14
|
+
|
|
15
|
+
params = {
|
|
16
|
+
v: @@version,
|
|
17
|
+
tid: tracking_code,
|
|
18
|
+
cid: client_id,
|
|
19
|
+
t: "event",
|
|
20
|
+
ec: category,
|
|
21
|
+
ea: action,
|
|
22
|
+
el: label,
|
|
23
|
+
ev: value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
self.hit( params )
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
def self.transaction( tracking_code, client_id, id, name, revenue, shipping = 0, tax = 0, currency = "USD", time = Time.now)
|
|
33
|
+
# report the time differene in miliseconds between event creation time and now
|
|
34
|
+
queue_time = (Time.now - time) * 1000
|
|
35
|
+
params = {
|
|
36
|
+
v: @@version,
|
|
37
|
+
tid: tracking_code,
|
|
38
|
+
cid: client_id,
|
|
39
|
+
t: "transaction",
|
|
40
|
+
qt: queue_time.to_s,
|
|
41
|
+
ti: id,
|
|
42
|
+
ta: name,
|
|
43
|
+
tr: revenue,
|
|
44
|
+
ts: shipping,
|
|
45
|
+
tt: tax,
|
|
46
|
+
cu: currency
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
self.hit( params )
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def self.hit( params )
|
|
58
|
+
begin
|
|
59
|
+
response = RestClient.post(@@endpoint, params )
|
|
60
|
+
return response.code
|
|
61
|
+
rescue RestClient::Exception => rex
|
|
62
|
+
return false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'server_side_ga/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "server_side_ga"
|
|
8
|
+
spec.version = ServerSideGa::VERSION
|
|
9
|
+
spec.authors = ["James Kennedy"]
|
|
10
|
+
spec.email = ["james@jameskennedy.ie"]
|
|
11
|
+
spec.description = %q{A wrapper for the Universal Analytics API}
|
|
12
|
+
spec.summary = %q{You can call ServerSideGa.event(category, action, client_id) to call}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
|
|
24
|
+
spec.add_dependency "rest-client"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: server_side_ga
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.0.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- James Kennedy
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2013-08-21 00:00:00 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: bundler
|
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ~>
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: "1.3"
|
|
23
|
+
type: :development
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: *id001
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
29
|
+
none: false
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: "0"
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: *id002
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: rest-client
|
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
40
|
+
none: false
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: "0"
|
|
45
|
+
type: :runtime
|
|
46
|
+
prerelease: false
|
|
47
|
+
version_requirements: *id003
|
|
48
|
+
description: A wrapper for the Universal Analytics API
|
|
49
|
+
email:
|
|
50
|
+
- james@jameskennedy.ie
|
|
51
|
+
executables: []
|
|
52
|
+
|
|
53
|
+
extensions: []
|
|
54
|
+
|
|
55
|
+
extra_rdoc_files: []
|
|
56
|
+
|
|
57
|
+
files:
|
|
58
|
+
- .gitignore
|
|
59
|
+
- Gemfile
|
|
60
|
+
- LICENSE.txt
|
|
61
|
+
- README.md
|
|
62
|
+
- Rakefile
|
|
63
|
+
- lib/server_side_ga.rb
|
|
64
|
+
- lib/server_side_ga/version.rb
|
|
65
|
+
- server_side_ga.gemspec
|
|
66
|
+
homepage: ""
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
hash: 3966672359818330374
|
|
80
|
+
segments:
|
|
81
|
+
- 0
|
|
82
|
+
version: "0"
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
none: false
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
hash: 3966672359818330374
|
|
89
|
+
segments:
|
|
90
|
+
- 0
|
|
91
|
+
version: "0"
|
|
92
|
+
requirements: []
|
|
93
|
+
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 1.8.25
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 3
|
|
98
|
+
summary: You can call ServerSideGa.event(category, action, client_id) to call
|
|
99
|
+
test_files: []
|
|
100
|
+
|