google_analytics_rails 0.1.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +49 -0
- data/Rakefile +34 -0
- data/app/helpers/google_analytics_rails_helper.rb +5 -0
- data/config/initializers/google_analytics_rails.rb +1 -0
- data/lib/assets/javascripts/google_analytics.coffee +52 -0
- data/lib/google_analytics_rails/engine.rb +4 -0
- data/lib/google_analytics_rails/version.rb +3 -0
- data/lib/google_analytics_rails.rb +5 -0
- data/lib/tasks/google_analytics_rails_tasks.rake +4 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c497ab25aabb660640bffa2856e9f78dd0f78f0
|
4
|
+
data.tar.gz: 1e329338f3a2cf06d11dafb894715c9ec9995fcc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c539291bd38c9a83f3c8acef4e562623205917f006cc5a21bfe40e6a348d005dfd203ea10aa1340a07ca07f0adb93120c9ed7b3fcf54f8fc4190f6dbd7bbb924
|
7
|
+
data.tar.gz: 494bbfeeb72355a3f1e39e84f1759e0928193b4646a0553505336f5b243d0d87aa16407c04dad9c01500f4f63435b6023f05cf6025281934a2e787da5a1b8924
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Almir Sarajčić
|
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,49 @@
|
|
1
|
+
# Google Analytics for Ruby on Rails
|
2
|
+
This gem helps with Google Analytics tracking. It supports Turbolinks 5.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'google_analytics_rails'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Add the following to your `application.js` file:
|
17
|
+
```
|
18
|
+
//= require google_analytics
|
19
|
+
```
|
20
|
+
|
21
|
+
Set `GOOGLE_ANALYTICS_ID` evironment variable.
|
22
|
+
You can add [`dotenv-rails` gem](https://github.com/bkeepers/dotenv) to set it using `.env` file. The file should look like this:
|
23
|
+
```
|
24
|
+
GOOGLE_ANALYTICS_ID=UA-123456-1
|
25
|
+
```
|
26
|
+
|
27
|
+
If you don't want to use environment variable you can create initializer
|
28
|
+
`config/initializers/google_analytics_rails.rb` containing:
|
29
|
+
```
|
30
|
+
GoogleAnalyticsRails.google_analytics_id = "YOUR GOOGLE ANALYTICS ID"
|
31
|
+
```
|
32
|
+
|
33
|
+
After that add this line to `<head>` in your layouts:
|
34
|
+
```
|
35
|
+
<%= google_analytics_meta_tag %>
|
36
|
+
```
|
37
|
+
Make sure you add it before `stylesheet_link_tag` and `javascript_include_tag`.
|
38
|
+
It will contain the meta tag with the ID you've set so it can be used from `google_analytics.coffee` file.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
If you find any bug or have an idea for improvement please create new PR or issue.
|
42
|
+
|
43
|
+
## License
|
44
|
+
google_analytics_rails gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
+
|
46
|
+
## Acknowledgments
|
47
|
+
Thanks to [@reed](https://github.com/reed) for tutorials:
|
48
|
+
http://reed.github.io/turbolinks-compatibility/google_analytics.html
|
49
|
+
http://reed.github.io/turbolinks-compatibility/google_universal_analytics.html
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GoogleAnalyticsRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1 @@
|
|
1
|
+
GoogleAnalyticsRails.google_analytics_id = ENV["GOOGLE_ANALYTICS_ID"]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class @GoogleAnalytics
|
2
|
+
@init: ->
|
3
|
+
@load()
|
4
|
+
|
5
|
+
ga "create", @analyticsId(), "auto"
|
6
|
+
|
7
|
+
if typeof Turbolinks isnt "undefined" and Turbolinks.supported
|
8
|
+
document.addEventListener "turbolinks:load", (->
|
9
|
+
@trackPageview()
|
10
|
+
), true
|
11
|
+
else
|
12
|
+
@trackPageview()
|
13
|
+
|
14
|
+
@load: ->
|
15
|
+
window.GoogleAnalyticsObject = "ga"
|
16
|
+
window.ga = window.ga or ->
|
17
|
+
window.ga.q = window.ga.q or []
|
18
|
+
window.ga.q.push arguments
|
19
|
+
window.ga.l = 1 * new Date
|
20
|
+
|
21
|
+
element = document.createElement("script")
|
22
|
+
element.async = true
|
23
|
+
element.src = "https://www.google-analytics.com/analytics.js"
|
24
|
+
|
25
|
+
selector = document.getElementsByTagName("script")[0]
|
26
|
+
selector.parentNode.insertBefore element, selector
|
27
|
+
|
28
|
+
@trackPageview: (url) ->
|
29
|
+
unless @isLocalRequest()
|
30
|
+
ga "set", "location", location.href.split("#")[0]
|
31
|
+
ga "send", "pageview",
|
32
|
+
title: document.title
|
33
|
+
|
34
|
+
@isLocalRequest: ->
|
35
|
+
@documentDomainIncludes "local"
|
36
|
+
|
37
|
+
@documentDomainIncludes: (str) ->
|
38
|
+
document.domain.indexOf(str) isnt -1
|
39
|
+
|
40
|
+
@analyticsId: ->
|
41
|
+
@findMetaElementByName("google-analytics-id").getAttribute("content")
|
42
|
+
|
43
|
+
@findMetaElementByName: (name) ->
|
44
|
+
elements = document.getElementsByTagName("meta")
|
45
|
+
|
46
|
+
for element in elements
|
47
|
+
if element.getAttribute("name") == name
|
48
|
+
return element
|
49
|
+
|
50
|
+
console.error("Could not find meta[name=" + name + "]")
|
51
|
+
|
52
|
+
GoogleAnalytics.init()
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_analytics_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Almir Sarajčić
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coffee-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- almir.sarajcic@icloud.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/helpers/google_analytics_rails_helper.rb
|
52
|
+
- config/initializers/google_analytics_rails.rb
|
53
|
+
- lib/assets/javascripts/google_analytics.coffee
|
54
|
+
- lib/google_analytics_rails.rb
|
55
|
+
- lib/google_analytics_rails/engine.rb
|
56
|
+
- lib/google_analytics_rails/version.rb
|
57
|
+
- lib/tasks/google_analytics_rails_tasks.rake
|
58
|
+
homepage: https://github.com/almirsarajcic/google_analytics_rails
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.5.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Google Analytics for Ruby on Rails
|
82
|
+
test_files: []
|