ga-love 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 +3 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +102 -0
- data/Rakefile +27 -0
- data/app/views/ga-love/_google_analytics_primary.html.haml +14 -0
- data/app/views/ga-love/_google_analytics_split_traffic.html.haml +100 -0
- data/app/views/ga-love/_index.html.haml +9 -0
- data/ga-love.gemspec +20 -0
- data/lib/ga-love.rb +5 -0
- data/lib/ga-love/version.rb +3 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 K$
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
ga-love
|
2
|
+
====================
|
3
|
+
A tool for generating click event tracking & cohorts using google analytics.
|
4
|
+
|
5
|
+
|
6
|
+
Installation Gemspec
|
7
|
+
------------
|
8
|
+
gem 'ga-love'
|
9
|
+
|
10
|
+
Create config/google_analytics.yml
|
11
|
+
|
12
|
+
development:
|
13
|
+
google_analytics_stream_id: <YOUR STREAM ACCOUNT ID>
|
14
|
+
google_analytics_id: <YOUR CLEAN ACCOUNT ID>
|
15
|
+
|
16
|
+
test:
|
17
|
+
...
|
18
|
+
|
19
|
+
production:
|
20
|
+
...
|
21
|
+
|
22
|
+
Create config/initializers/app_config.rb
|
23
|
+
|
24
|
+
AppConfig = YAML.load_file(Rails.root.join('config', 'google_analytics.yml'))
|
25
|
+
|
26
|
+
# Override config options by correct environment
|
27
|
+
env_options = AppConfig.delete(Rails.env)
|
28
|
+
|
29
|
+
AppConfig.merge!(env_options) unless env_options.nil?
|
30
|
+
|
31
|
+
Include in your layout
|
32
|
+
|
33
|
+
= render(:partial => "ga-love/index")
|
34
|
+
|
35
|
+
Sample Use
|
36
|
+
------------------
|
37
|
+
Clicks are tracked to `<YOUR STREAM ACCOUNT>` and pageviews are logged to `<YOUR CLEAN ACCOUNT>`. The following
|
38
|
+
elements are tracked by default:
|
39
|
+
|
40
|
+
* .pinit
|
41
|
+
* a
|
42
|
+
* input[type=submit]
|
43
|
+
* input[type=button]
|
44
|
+
* button
|
45
|
+
|
46
|
+
You can add custom data to each click event by setting an object in your controller. This example logs data that would be useful in making a cohort analysis.
|
47
|
+
|
48
|
+
class ApplicationController < ActionController::Base
|
49
|
+
...
|
50
|
+
before_filter :ga_stuff
|
51
|
+
...
|
52
|
+
def ga_stuff
|
53
|
+
@ga_url = URI.parse(request.fullpath)
|
54
|
+
@ga_url.query ||= ""
|
55
|
+
session[:session_id] ||= nil
|
56
|
+
@ga_user = {:session_id => request.session_options[:id]}
|
57
|
+
if user_signed_in?
|
58
|
+
@ga_user.merge!( {
|
59
|
+
:id => current_user.id,
|
60
|
+
:signed_up_at => current_user.created_at.strftime("%-d-%-m-%Y"),
|
61
|
+
:login_count => current_user.login_count
|
62
|
+
})
|
63
|
+
end
|
64
|
+
@ga_url.query += "&#{@ga_user.to_query}"
|
65
|
+
end
|
66
|
+
...
|
67
|
+
end
|
68
|
+
|
69
|
+
To Do
|
70
|
+
------------------
|
71
|
+
|
72
|
+
* remove .pinit
|
73
|
+
* offer a way to add classes/elements
|
74
|
+
|
75
|
+
|
76
|
+
Submitting an Issue
|
77
|
+
-------------------
|
78
|
+
We use the [GitHub issue tracker](http://github.com/kdmny/ga-love/issues) to track bugs and
|
79
|
+
features. Before submitting a bug report or feature request, check to make sure it hasn't already
|
80
|
+
been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
|
81
|
+
bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
|
82
|
+
details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
|
83
|
+
operating system. Ideally, a bug report should include a pull request with failing specs.
|
84
|
+
|
85
|
+
|
86
|
+
Submitting a Pull Request
|
87
|
+
-------------------------
|
88
|
+
1. Fork the project.
|
89
|
+
2. Create a topic branch.
|
90
|
+
3. Implement your feature or bug fix.
|
91
|
+
4. Add documentation for your feature or bug fix.
|
92
|
+
5. Run <tt>rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
|
93
|
+
6. Add specs for your feature or bug fix.
|
94
|
+
7. Run <tt>rake spec</tt>. If your changes are not 100% covered, go back to step 6.
|
95
|
+
8. Commit and push your changes.
|
96
|
+
9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
97
|
+
|
98
|
+
|
99
|
+
Copyright
|
100
|
+
---------
|
101
|
+
Copyright (c) 2013 K$.
|
102
|
+
See [LICENSE](https://github.com/kdmny/ga-love/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
namespace :doc do
|
10
|
+
begin
|
11
|
+
require 'yard'
|
12
|
+
rescue LoadError
|
13
|
+
# ignore
|
14
|
+
else
|
15
|
+
YARD::Rake::YardocTask.new do |task|
|
16
|
+
task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
|
17
|
+
task.options = [
|
18
|
+
'--protected',
|
19
|
+
'--output-dir', 'doc/yard',
|
20
|
+
'--tag', 'format:Supported formats',
|
21
|
+
'--tag', 'authenticated:Requires Authentication',
|
22
|
+
'--tag', 'rate_limited:Rate Limited',
|
23
|
+
'--markup', 'markdown',
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- if Rails.env.production?
|
2
|
+
:javascript
|
3
|
+
try {
|
4
|
+
var _gaq = _gaq || [];
|
5
|
+
_gaq.push(['_setAccount', #{AppConfig["google_analytics_stream_id"]}]);
|
6
|
+
_gaq.push(['_trackPageview', "#{url}"]);
|
7
|
+
} catch(err) {$('#ga_errors').append("<p>" + err + "</p>");}
|
8
|
+
|
9
|
+
|
10
|
+
:javascript
|
11
|
+
var _gaq = _gaq || [];
|
12
|
+
_gaq.push(['_setAccount', '#{AppConfig["google_analytics_id"]}']);
|
13
|
+
_gaq.push(['_setDomainName', '#{HOST}']);
|
14
|
+
_gaq.push(['_trackPageview']);
|
@@ -0,0 +1,100 @@
|
|
1
|
+
- if @error_404
|
2
|
+
- url = "/404?page=#{request.fullpath}&from=#{request.referer}"
|
3
|
+
- else
|
4
|
+
- url = URI.parse(request.fullpath)
|
5
|
+
- url.query ||= "ga=1"
|
6
|
+
- if @ga_user
|
7
|
+
- url.query += "&#{@ga_user.to_query}"
|
8
|
+
|
9
|
+
:javascript
|
10
|
+
var debug_on = /debug/i.test($(location).attr('href').toLowerCase());
|
11
|
+
|
12
|
+
function class_type_or_click(element){
|
13
|
+
var this_is_sparta ="click:";
|
14
|
+
var story_id = "";
|
15
|
+
var story = $(element).parents(".item.active, .story");
|
16
|
+
if(story.length > 0){
|
17
|
+
story_id = "story_" + $(story[0]).get(0).id.split("_")[1];
|
18
|
+
}
|
19
|
+
var val = $(element).attr("value");
|
20
|
+
var tag_name = $(element).get(0).tagName;
|
21
|
+
var text_val = $(element).text();
|
22
|
+
var alt = $(element).attr("alt");
|
23
|
+
var data = [val, text_val, tag_name, alt, story_id];
|
24
|
+
|
25
|
+
data = _.select(data, function(e){
|
26
|
+
return !_.isNull(e) && !_.isUndefined(e);
|
27
|
+
});
|
28
|
+
this_is_sparta += _.map(data, function(e){return e.replace(/\n*/, "");}).join(":");
|
29
|
+
|
30
|
+
return this_is_sparta.replace(/\s+/g,'_');
|
31
|
+
}
|
32
|
+
|
33
|
+
function build_ga_string(element){
|
34
|
+
var build_ga;
|
35
|
+
var recursion = false;
|
36
|
+
|
37
|
+
build_ga = class_type_or_click(element);
|
38
|
+
|
39
|
+
var parent_list = $(element).parents();
|
40
|
+
|
41
|
+
if(recursion){
|
42
|
+
parent_list.each(function(index){
|
43
|
+
build_ga += '-' + class_type_or_click(this);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
return build_ga;
|
48
|
+
}
|
49
|
+
|
50
|
+
function submit_ga_string(element, built_ga){
|
51
|
+
if(!_.isNull(element)){
|
52
|
+
built_ga = build_ga_string(element);
|
53
|
+
}
|
54
|
+
uri_encoded_ga = encodeURI(built_ga);
|
55
|
+
var ts = new Date().getTime();
|
56
|
+
post_to_ga = "#{url}&ts=" + ts +"&additional=["+uri_encoded_ga;
|
57
|
+
|
58
|
+
post_to_ga += "]";
|
59
|
+
|
60
|
+
|
61
|
+
try{
|
62
|
+
if('#{Rails.env.to_s}' == "production"){
|
63
|
+
if(debug_on){
|
64
|
+
log(post_to_ga);
|
65
|
+
}
|
66
|
+
|
67
|
+
_gaq.push(['_setAccount', '#{AppConfig["google_analytics_stream_id"]}']);
|
68
|
+
_gaq.push(['_trackPageview', post_to_ga]);
|
69
|
+
}else{
|
70
|
+
log(post_to_ga);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
catch(err){
|
74
|
+
$('#ga_errors').append("<p>" + err + "</p>");
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
function generate_ga_from_element(element){
|
79
|
+
//currently unused for GA. Kept for obvious reasons
|
80
|
+
var clazz = $(element).attr("class");
|
81
|
+
|
82
|
+
var this_is_sparta_unused ="";
|
83
|
+
if (clazz){
|
84
|
+
this_is_sparta_unused += clazz.replace(/\s+/g, ':');
|
85
|
+
}else{
|
86
|
+
if(tag_name == "A"){
|
87
|
+
this_is_sparta_unused += "["+$(element).text().replace(/\s+/g,'_')+"-to-" + $(element).attr('href') +"]";
|
88
|
+
}else{
|
89
|
+
this_is_sparta_unused += tag_name;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
return this_is_sparta_unused;
|
94
|
+
}
|
95
|
+
$(".pinit").live("click", function (e){ log("pin it liv");submit_ga_string(this); e.stopPropagation();e.preventDefault();return false; });
|
96
|
+
$("a").live("click", function (e){ log("a liv");if(!$(e.target).parent().hasClass("pin-container")){submit_ga_string(this);} });
|
97
|
+
|
98
|
+
$("input[type=submit]").live("click", function (){ submit_ga_string(this); });
|
99
|
+
$("input[type=button]").live("click", function (){ log("submitting ga string for input button");submit_ga_string(this); });
|
100
|
+
$("button").live("click", function (){ log("submitting ga string for input button");submit_ga_string(this); });
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- @ga_url ||= ""
|
2
|
+
#ga_errors.hidden
|
3
|
+
:javascript
|
4
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
5
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
6
|
+
|
7
|
+
|
8
|
+
= render :partial => 'ga-love/google_analytics_split_traffic', :locals => {:url => @ga_url}
|
9
|
+
= render :partial => 'ga-love/google_analytics_primary', :locals => {:url => @ga_url}
|
data/ga-love.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ga-love/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.add_development_dependency('rspec', '~> 2.4')
|
6
|
+
s.add_development_dependency('yard')
|
7
|
+
s.authors = ["K$"]
|
8
|
+
s.description = %q{A tool for generating click event tracking & cohorts using google analytics.}
|
9
|
+
s.email = ['kdmny30@gmail.com']
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.homepage = 'https://github.com/kdmny/ga-love'
|
12
|
+
s.name = 'ga-love'
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
16
|
+
s.rubyforge_project = s.name
|
17
|
+
s.summary = %q{A tool for generating click event tracking & cohorts using google analytics.}
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.version = GaLove::VERSION
|
20
|
+
end
|
data/lib/ga-love.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ga-love
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- K$
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70217854174540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.4'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70217854174540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
requirement: &70217854174000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70217854174000
|
36
|
+
description: A tool for generating click event tracking & cohorts using google analytics.
|
37
|
+
email:
|
38
|
+
- kdmny30@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE.md
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- app/views/ga-love/_google_analytics_primary.html.haml
|
49
|
+
- app/views/ga-love/_google_analytics_split_traffic.html.haml
|
50
|
+
- app/views/ga-love/_index.html.haml
|
51
|
+
- ga-love.gemspec
|
52
|
+
- lib/ga-love.rb
|
53
|
+
- lib/ga-love/version.rb
|
54
|
+
homepage: https://github.com/kdmny/ga-love
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.3.6
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: ga-love
|
74
|
+
rubygems_version: 1.8.15
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: A tool for generating click event tracking & cohorts using google analytics.
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|