customized_piwik_analytics 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7855a538599330537096331cb4d37acc084ec363
4
+ data.tar.gz: 1f1fde77b4cca3b10681924ea34a6963bc090e3e
5
+ SHA512:
6
+ metadata.gz: 91cef5ba9ae82f5d435db5018296963cd4cadaaaae62c8e58ebee850a1dde9b3b3c8eee79b615e25e3b9246022837e9257594eb1e9d9deec27ec74976a4da667
7
+ data.tar.gz: b07fbe742cf2917f18fefd2bc9248ea242d8808b5a5fda88e77dc441741330ad2a8e092d2547c389b5b4e74677f028a2c2ab6625b057eef52b1c4b4d3d1d64fa
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea/*
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - ree
11
+ gemfile: Gemfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Fabian Becker
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.
@@ -0,0 +1,39 @@
1
+ {<img src="https://travis-ci.org/halfdan/piwik_analytics.png?branch=master" alt="Build Status" />}[https://travis-ci.org/halfdan/piwik_analytics]
2
+
3
+ = PiwikAnalytics
4
+
5
+ <b>Note:</b> This Gem has undergone a major rewrite in 1.x compared to 0.9.x.
6
+
7
+ The customized_piwik_analytics gem provides an easy way to include Piwik into your application.
8
+ By default it will output the synchronous piwik tracking code for every page
9
+ (given that it is configured correctly).
10
+ In this version added option for specify protocol (http/https/etc) for Piwik requests.
11
+
12
+ == Installation
13
+
14
+ Add `customized_piwik_analytics` to Gemfile:
15
+
16
+ gem 'customized_piwik_analytics', '~> 1.0.0'
17
+
18
+ Run the generator:
19
+
20
+ rails g piwik_analytics:install
21
+
22
+ This will install a piwik.yml configuration file into the `config` directory
23
+ of your application.
24
+
25
+
26
+ == Configuration
27
+
28
+ Open up `config/piwik.yml` and edit the settings. Each setting is described in
29
+ the config file itself.
30
+ Additionally there is a 'protocol' option. It allows to set differ protocol for
31
+ analytical requests. By default it work the same way as parent variant of the gem.
32
+
33
+ == Usage
34
+
35
+ Inside your `application.html.erb` (or haml, slim) simply add
36
+
37
+ <%= piwik_tracking_tag %>
38
+
39
+ Enjoy :)
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ task :default => :spec
10
+
11
+ desc 'Generate documentation for the customized_piwik_analytics plugin.'
12
+ Rake::RDocTask.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'rdoc'
14
+ rdoc.title = 'CustomizedPiwikAnalytics'
15
+ rdoc.options << '--line-numbers' << '--inline-source'
16
+ rdoc.rdoc_files.include('README')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
@@ -0,0 +1,22 @@
1
+ <!-- Piwik -->
2
+ <script type="text/javascript">
3
+ <% if protocol.present? %>
4
+ var protocol = "<%= protocol %>";
5
+ <% else %>
6
+ var protocol = ("https:" == document.location.protocol) ? "https" : "http";
7
+ <% end %>
8
+ var pkBaseURL = protocol + "://<%= url %>/";
9
+ document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
10
+ </script><script type="text/javascript">
11
+ try {
12
+ var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", <%= id_site %>);
13
+ piwikTracker.trackPageView();
14
+ piwikTracker.enableLinkTracking();
15
+ } catch( err ) {}
16
+ </script>
17
+ <!-- End Piwik Tag -->
18
+ <!-- Piwik Image Tracker -->
19
+ <noscript>
20
+ <p><img src="//<%= url %>/piwik.php?idsite=<%= id_site %>&amp;rec=1" style="border:0" alt="" /></p>
21
+ </noscript>
22
+ <!-- End Piwik -->
@@ -0,0 +1,31 @@
1
+ <!-- Piwik -->
2
+ <script type="text/javascript">
3
+ var _paq = _paq || [];
4
+ _paq.push(["trackPageView"]);
5
+ _paq.push(["enableLinkTracking"]);
6
+
7
+ (function() {
8
+ <% if protocol.present? %>
9
+ var protocol = '<%= protocol %>';
10
+ <% else %>
11
+ var protocol = ("https:" == document.location.protocol) ? "https" : "http";
12
+ <% end %>
13
+ var u = protocol + "://<%= url %>/";
14
+ _paq.push(["setTrackerUrl", u+"piwik.php"]);
15
+ _paq.push(["setSiteId", <%= id_site %>]);
16
+ var d=document,
17
+ g=d.createElement("script"),
18
+ s=d.getElementsByTagName("script")[0];
19
+ g.type="text/javascript";
20
+ g.defer=true;
21
+ g.async=true;
22
+ g.src=u+"piwik.js";
23
+ s.parentNode.insertBefore(g,s);
24
+ })();
25
+ </script>
26
+ <!-- End Piwik Tag -->
27
+ <!-- Piwik Image Tracker -->
28
+ <noscript>
29
+ <p><img src="//<%= url %>/piwik.php?idsite=<%= id_site %>&amp;rec=1" style="border:0" alt="" /></p>
30
+ </noscript>
31
+ <!-- End Piwik -->
@@ -0,0 +1,27 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'customized_piwik_analytics'
3
+ s.version = '1.0.4'
4
+ s.date = Time.now.strftime "%Y-%m-%d"
5
+ s.author = 'Fabian Becker, Ivan Zabrovskiy'
6
+ s.email = 'halfdan@xnorfz.de'
7
+ s.homepage = 'https://github.com/Loriowar/piwik-ruby-tracking'
8
+ s.summary = "[Rails] Easily include Piwik tracking in your Rails application."
9
+
10
+ s.description = <<-DESC
11
+ The customized_piwik_analytics gem provides an easy way to include Piwik into your application.
12
+ By default it will output the synchronous piwik tracking code for every page
13
+ (given that it is configured correctly).
14
+ In this version add option for specify protocol (http/https/etc) for Piwik requests.
15
+ DESC
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'rails', '>= 3.0.0'
22
+ s.add_dependency 'actionpack'
23
+ s.add_dependency 'activesupport'
24
+
25
+ s.add_development_dependency "rspec", "~> 2.12.0"
26
+ end
27
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/lib/customized_piwik_analytics"
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'piwik_analytics', 'configuration')
2
+
3
+ module PiwikAnalytics
4
+ require 'piwik_analytics/engine' if defined?(Rails)
5
+
6
+ class <<self
7
+ attr_writer :configuration
8
+
9
+ def configuration
10
+ @configuration ||= PiwikAnalytics::Configuration.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module PiwikAnalytics
2
+ module Generators
3
+ class Base < Rails::Generators::NamedBase
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'piwik_analytics', generator_name, 'templates'))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module PiwikAnalytics
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ def self.source_root
5
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
6
+ end
7
+ def copy_config_file
8
+ template 'config/piwik.yml'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ # Configuration:
2
+ #
3
+ # disabled
4
+ # false if tracking tag should be shown
5
+ # use_async
6
+ # Set to true if you want to use asynchronous tracking
7
+ # url
8
+ # The url of your piwik instance (e.g. localhost/piwik/)
9
+ # id_site
10
+ # The id of your website inside Piwik
11
+ # protocol
12
+ # The protocol for requests to the Piwik (e.g. http)
13
+ #
14
+ production:
15
+ piwik:
16
+ id_site: 1
17
+ url: localhost
18
+ disabled: false
19
+ use_async: false
20
+
21
+ development:
22
+ piwik:
23
+ id_site: 1
24
+ url: localhost
25
+ disabled: true
26
+ use_async: false
27
+ hostname: localhost
28
+
29
+ test:
30
+ piwik:
31
+ id_site: 1
32
+ url: localhost
33
+ disabled: true
34
+ use_async: false
35
+ hostname: localhost
@@ -0,0 +1,81 @@
1
+ module PiwikAnalytics
2
+ class Configuration
3
+
4
+ #
5
+ # The url of the Piwik instance
6
+ # Defaults to localhost
7
+ #
8
+ def url
9
+ @url ||= (user_configuration_from_key('url') || 'localhost')
10
+ end
11
+
12
+ #
13
+ # The protocol for requests to the Piwik
14
+ # Defaults to nil
15
+ #
16
+ def protocol
17
+ @protocol ||= user_configuration_from_key('protocol')
18
+ end
19
+
20
+ #
21
+ # The ID of the tracked website
22
+ # Defaults to 1
23
+ #
24
+ def id_site
25
+ @id_site ||= (user_configuration_from_key('id_site') || 1)
26
+ end
27
+
28
+ #
29
+ # Whether or not to use the async tracking
30
+ # Defaults to false
31
+ #
32
+ def use_async?
33
+ @use_async ||= (user_configuration_from_key('use_async') || false)
34
+ end
35
+
36
+ #
37
+ # Whether or not to disable Piwik.
38
+ # Defaults to false.
39
+ #
40
+ def disabled?
41
+ @disabled ||= (user_configuration_from_key('disabled') || false)
42
+ end
43
+
44
+ private
45
+
46
+ #
47
+ # return a specific key from the user configuration in config/piwik.yml
48
+ #
49
+ # ==== Returns
50
+ #
51
+ # Mixed:: requested_key or nil
52
+ #
53
+ def user_configuration_from_key( *keys )
54
+ keys.inject(user_configuration) do |hash, key|
55
+ hash[key] if hash
56
+ end
57
+ end
58
+
59
+ #
60
+ # Memoized hash of configuration options for the current Rails environment
61
+ # as specified in config/piwik.yml
62
+ #
63
+ # ==== Returns
64
+ #
65
+ # Hash:: configuration options for current environment
66
+ #
67
+ def user_configuration
68
+ @user_configuration ||= begin
69
+ path = File.join(::Rails.root, 'config', 'piwik.yml')
70
+ if File.exist?(path)
71
+ File.open(path) do |file|
72
+ processed = ERB.new(file.read).result
73
+ YAML.load(processed)[::Rails.env]['piwik']
74
+ end
75
+ else
76
+ {}
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ # PiwikAnalytics
2
+ require 'active_support'
3
+
4
+ module PiwikAnalytics
5
+
6
+ class Piwik < Rails::Engine
7
+ engine_name :piwik_analytics
8
+
9
+ paths["app/views"]
10
+
11
+ generators do
12
+ load "generators/piwik_analytics.rb"
13
+ end
14
+
15
+ initializer "piwik_analytics.init", :before=> :load_config_initializers do
16
+ require "piwik_analytics/helpers"
17
+ load "piwik_analytics/init.rb"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module PiwikAnalytics
2
+ module Helpers
3
+ def piwik_tracking_tag
4
+ config = PiwikAnalytics.configuration
5
+ return if config.disabled?
6
+
7
+ if config.use_async?
8
+ file = "piwik_analytics/piwik_tracking_tag_async"
9
+ else
10
+ file = "piwik_analytics/piwik_tracking_tag"
11
+ end
12
+ render({
13
+ file: file,
14
+ locals: {url: config.url,
15
+ id_site: config.id_site,
16
+ protocol: config.protocol}
17
+ })
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ ActionView::Base.send :include, PiwikAnalytics::Helpers
@@ -0,0 +1,27 @@
1
+ require "piwik_analytics/configuration"
2
+
3
+ describe PiwikAnalytics::Configuration do
4
+ before(:each) do
5
+ conf_mock = {
6
+ "id_site" => 4,
7
+ "url" => "example.com",
8
+ "use_async" => true,
9
+ "disabled" => true
10
+ }
11
+
12
+ @config = PiwikAnalytics::Configuration.new
13
+ @config.stub(:user_configuration).and_return(conf_mock)
14
+ end
15
+ it "returns a id_site" do
16
+ @config.id_site.should eq 4
17
+ end
18
+ it "returns a url" do
19
+ @config.url.should eq "example.com"
20
+ end
21
+ it "has a use_async? flag" do
22
+ @config.use_async?.should be_true
23
+ end
24
+ it "has a disabled? flag" do
25
+ @config.disabled?.should be_true
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ require "piwik_analytics/helpers"
2
+
3
+ class HelpersDouble
4
+ include PiwikAnalytics::Helpers
5
+ end
6
+
7
+ describe PiwikAnalytics::Helpers do
8
+ describe "#piwik_tracking_tag" do
9
+ before(:each) do
10
+ @config = mock("Configuration").as_null_object
11
+ @double = HelpersDouble.new
12
+ end
13
+
14
+ context "disabled" do
15
+ it 'should return nil if disabled' do
16
+ @config.stub(:disabled?).and_return true
17
+ PiwikAnalytics.stub(:configuration).and_return @config
18
+ @double.piwik_tracking_tag.should be_nil
19
+ end
20
+ end
21
+
22
+ context "enabled" do
23
+ before(:each) do
24
+ @config.stub(:disabled?).and_return false
25
+ end
26
+
27
+ it 'should render' do
28
+ PiwikAnalytics.stub(:configuration).and_return @config
29
+ @double.should_receive(:render)
30
+ @double.piwik_tracking_tag
31
+ end
32
+
33
+ it 'should use file piwik_tracking_tag_async when async' do
34
+ @config.stub(:use_async?).and_return true
35
+ PiwikAnalytics.stub(:configuration).and_return @config
36
+
37
+ @double.should_receive(:render).with(hash_including(:file => 'piwik_analytics/piwik_tracking_tag_async'))
38
+ @double.piwik_tracking_tag
39
+ end
40
+
41
+ it 'should use file piwik_tracking_tag when not async' do
42
+ @config.stub(:use_async?).and_return false
43
+ PiwikAnalytics.stub(:configuration).and_return @config
44
+
45
+ @double.should_receive(:render).with(hash_including(:file => 'piwik_analytics/piwik_tracking_tag'))
46
+ @double.piwik_tracking_tag
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ require "erb"
2
+
3
+ describe "views/piwik_tracking_tag.html.erb" do
4
+ before(:each) do
5
+ filename = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views', 'piwik_analytics', 'piwik_tracking_tag.html.erb')
6
+ @template = ERB.new(File.read(filename))
7
+ end
8
+
9
+ it "should render url" do
10
+ url = "example.com"
11
+ id_site = nil
12
+ @template.result(binding).should =~ /:\/\/example.com/
13
+ end
14
+
15
+ it "should render id_site" do
16
+ url = nil
17
+ id_site = 4
18
+ @template.result(binding).should =~ /"piwik\.php", 4/
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require "erb"
2
+
3
+ describe "views/piwik_tracking_tag_async.html.erb" do
4
+ before(:each) do
5
+ filename = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views', 'piwik_analytics', 'piwik_tracking_tag_async.html.erb')
6
+ @template = ERB.new(File.read(filename))
7
+ end
8
+
9
+ it "should render url" do
10
+ url = "example.com"
11
+ id_site = nil
12
+ @template.result(binding).should =~ /:\/\/example.com/
13
+ end
14
+
15
+ it "should render id_site" do
16
+ url = nil
17
+ id_site = 4
18
+ @template.result(binding).should =~ /"setSiteId", 4/
19
+ end
20
+ end
21
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: customized_piwik_analytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Fabian Becker, Ivan Zabrovskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 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: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.12.0
69
+ description: |2
70
+ The customized_piwik_analytics gem provides an easy way to include Piwik into your application.
71
+ By default it will output the synchronous piwik tracking code for every page
72
+ (given that it is configured correctly).
73
+ In this version add option for specify protocol (http/https/etc) for Piwik requests.
74
+ email: halfdan@xnorfz.de
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - .travis.yml
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - MIT-LICENSE
84
+ - README.rdoc
85
+ - Rakefile
86
+ - app/views/piwik_analytics/piwik_tracking_tag.html.erb
87
+ - app/views/piwik_analytics/piwik_tracking_tag_async.html.erb
88
+ - customized_piwik_analytics.gemspec
89
+ - init.rb
90
+ - lib/customized_piwik_analytics.rb
91
+ - lib/generators/piwik_analytics.rb
92
+ - lib/generators/piwik_analytics/install/install_generator.rb
93
+ - lib/generators/piwik_analytics/install/templates/config/piwik.yml
94
+ - lib/piwik_analytics/configuration.rb
95
+ - lib/piwik_analytics/engine.rb
96
+ - lib/piwik_analytics/helpers.rb
97
+ - lib/piwik_analytics/init.rb
98
+ - spec/configuration_spec.rb
99
+ - spec/helpers_spec.rb
100
+ - spec/views/piwik_tracking_tag.html.erb_spec.rb
101
+ - spec/views/piwik_tracking_tag_async.html.erb_spec.rb
102
+ homepage: https://github.com/Loriowar/piwik-ruby-tracking
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: '[Rails] Easily include Piwik tracking in your Rails application.'
125
+ test_files: []
126
+ has_rdoc: