Support piwik.embed directive
Change-Id: I3abb4d35ae398967146b37d1f38d451cdf50ed41
diff --git a/Makefile.PL b/Makefile.PL
index 6a0def1..b74081e 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -22,10 +22,12 @@
'Mojolicious::Plugin::MailException' => 0.20,
'Mojolicious::Plugin::CHI' => 0.15,
'Mojolicious::Plugin::ClientIP' => 0.01,
- 'Mojolicious::Plugin::Piwik' => 0.20,
'Cache::FastMmap' => 0,
'Mojo::JWT' => 0.05,
+ # Required for bundled plugins
+ 'Mojolicious::Plugin::Piwik' => 0.24,
+
# Currently on GitHub only (github.com/akron)
'Mojolicious::Plugin::Localize' => 0.20,
'Mojolicious::Plugin::TagHelpers::ContentBlock' => 0.08,
diff --git a/lib/Kalamar/Plugin/Piwik.pm b/lib/Kalamar/Plugin/Piwik.pm
index 2bc5547..8bdcd1d 100644
--- a/lib/Kalamar/Plugin/Piwik.pm
+++ b/lib/Kalamar/Plugin/Piwik.pm
@@ -27,13 +27,15 @@
# Add event handler for korap requests
$mojo->content_block(scripts => {
inline => <<'SCRIPT'
-%= javascript begin
+% if (stash('piwik.embed')) {
+ %= javascript begin
window.addEventListener('korapRequest', function(e) {
_paq.push(['setReferrerUrl', location.href]);
_paq.push(['setCustomUrl', e.detail.url]);
_paq.push(['trackPageView']);
});
-% end
+ % end
+% }
SCRIPT
});
};
diff --git a/t/plugin/piwik.t b/t/plugin/piwik.t
index 69cd401..28c770b 100644
--- a/t/plugin/piwik.t
+++ b/t/plugin/piwik.t
@@ -22,4 +22,20 @@
->content_like(qr!window\.addEventListener\('korapRequest!)
;
+# No embedding
+$t->app->plugin('Piwik' => {
+ url => 'https://piwik.korap.ids-mannheim.de/',
+ site_id => 1,
+ embed => 0
+});
+
+$t->get_ok('/doc/faq')
+ ->status_is(200)
+ ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
+ ->element_exists_not('section[name=piwik-opt-out] iframe')
+ ->content_unlike(qr!var _paq!)
+ ->content_unlike(qr!window\.addEventListener\('korapRequest!)
+ ;
+
+
done_testing();