mirror of
https://github.com/hendrikschneider/jekyll-analytics
synced 2025-02-27 04:17:13 +00:00
unittests added
This commit is contained in:
parent
06b15c1b31
commit
d7f70cb73f
7 changed files with 82 additions and 4 deletions
1
.travis.yml
Normal file
1
.travis.yml
Normal file
|
@ -0,0 +1 @@
|
|||
language: ruby
|
10
README.md
10
README.md
|
@ -18,7 +18,7 @@ gem 'jekyll-analytics'
|
|||
```
|
||||
Then execute
|
||||
```
|
||||
bundle
|
||||
$ bundle
|
||||
```
|
||||
Or install it yourself
|
||||
```
|
||||
|
@ -36,11 +36,11 @@ Configure the plugin in `_config.yml` by adding:
|
|||
|
||||
```yml
|
||||
jekyll_analytics:
|
||||
GoogleAnalytics: # Add these if you want to track with Google Analytics
|
||||
GoogleAnalytics: # Add, if you want to track with Google Analytics
|
||||
id: UA-123-456 # Required - replace with your tracking id
|
||||
anonymizeIp: false # Optional - Default: false - set to true for anonymized tracking
|
||||
|
||||
Piwik: # Add these if you want to track with Piwik
|
||||
Piwik: # Add, if you want to track with Piwik
|
||||
url: piwik.example.com # Required - url to piwik installation without trailing /
|
||||
siteId: "1234" # Required - replace with your piwik site id (Write id as string)
|
||||
```
|
||||
|
@ -49,7 +49,9 @@ jekyll_analytics:
|
|||
Tracking will be disabled in development mode. To enable production mode set enviroment variable JEKYLL_ENV=production.
|
||||
Github pages automatically sets JEKYLL_ENV to production.
|
||||
For testing use
|
||||
```JEKYLL_ENV=production jekyll serve```
|
||||
```
|
||||
$JEKYLL_ENV=production jekyll serve
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
5
Rakefile
Normal file
5
Rakefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
task :run_unit_test do
|
||||
require_relative "test/test_all.rb"
|
||||
end
|
||||
|
||||
task :default => 'run_unit_test'
|
3
lib/analytics/Analytics.rb
Normal file
3
lib/analytics/Analytics.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Analytics
|
||||
|
||||
end
|
34
test/GoogleAnalyticsTest.rb
Normal file
34
test/GoogleAnalyticsTest.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require_relative "../lib/analytics/GoogleAnalytics.rb"
|
||||
require "test/unit"
|
||||
|
||||
class TestGoogleAnalytics < Test::Unit::TestCase
|
||||
def test_init
|
||||
assert_raise( ArgumentError ) { GoogleAnalytics.new( {"id" => "123-456"} ) }
|
||||
assert_instance_of(GoogleAnalytics, GoogleAnalytics.new( {"id" => "UA-123-456"} ))
|
||||
end
|
||||
|
||||
def test_default_tracking_string
|
||||
googleAnalytics = GoogleAnalytics.new( {"id" => "UA-123-456"} )
|
||||
assert_equal(googleAnalytics.render(),
|
||||
"""
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-123-456', 'auto');
|
||||
\tga('send', 'pageview');
|
||||
\tga('set', 'anonymizeIp', false);
|
||||
</script>
|
||||
<!-- End Google Analytics -->
|
||||
""")
|
||||
end
|
||||
|
||||
def test_anonymize_true
|
||||
googleAnalytics = GoogleAnalytics.new( {"id" => "UA-123-456", "anonymizeIp" => true} )
|
||||
assert_match(/\('set', 'anonymizeIp', false\);/, googleAnalytics.render())
|
||||
end
|
||||
|
||||
end
|
31
test/PiwikTest.rb
Normal file
31
test/PiwikTest.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require_relative "../lib/analytics/Piwik.rb"
|
||||
require "test/unit"
|
||||
|
||||
class PiwikTest < Test::Unit::TestCase
|
||||
def test_init
|
||||
assert_raise( ArgumentError ) { Piwik.new( {"url" => "my.piwik.server/path/"}) }
|
||||
assert_raise( ArgumentError ) { Piwik.new( {"url" => "my.piwik.server/path", "siteId" => "a"}) }
|
||||
assert_instance_of(Piwik, Piwik.new( {"url" => "my.piwik.server/path", "siteId" => "1"}) )
|
||||
end
|
||||
|
||||
def test_default_tracking_string
|
||||
piwikAnalytics = Piwik.new( {"url" => "my.piwik.server/path", "siteId" => "1"})
|
||||
assert_equal(piwikAnalytics.render(),
|
||||
"""
|
||||
<!-- Piwik -->
|
||||
<script type=\"text/javascript\">
|
||||
var _paq = _paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
var u=\"my.piwik.server/path\";
|
||||
_paq.push(['setTrackerUrl', u+'/piwik.php']);
|
||||
_paq.push(['setSiteId', '1']);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
</script>
|
||||
<!-- End Piwik Code -->
|
||||
""")
|
||||
end
|
||||
end
|
2
test/test_all.rb
Normal file
2
test/test_all.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require_relative "GoogleAnalyticsTest"
|
||||
require_relative "PiwikTest"
|
Loading…
Add table
Reference in a new issue