Mercurial > kallithea
changeset 4462:fb5760e8ba43
support other analytic systems then just Google Analytics
Fallback to Google Analytics code if the string starts with "UA-"
author | domruf <dominikruf@gmail.com> |
---|---|
date | Mon, 18 Aug 2014 21:04:36 +0200 |
parents | d6e96730edfb |
children | d2f71ee1c738 |
files | kallithea/lib/base.py kallithea/templates/admin/settings/settings_global.html kallithea/templates/base/root.html |
diffstat | 3 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/base.py Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/lib/base.py Mon Aug 18 21:04:36 2014 +0200 @@ -305,6 +305,19 @@ c.visual.gravatar_url = rc_config.get('gravatar_url') c.ga_code = rc_config.get('ga_code') + # TODO: replace undocumented backwards compatibility hack with db upgrade and rename ga_code + if c.ga_code and '<' not in c.ga_code: + c.ga_code = '''<script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', '%s']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script>''' % c.ga_code c.site_name = rc_config.get('title') c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl')
--- a/kallithea/templates/admin/settings/settings_global.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/admin/settings/settings_global.html Mon Aug 18 21:04:36 2014 +0200 @@ -24,10 +24,11 @@ <div class="field"> <div class="label"> - <label for="ga_code">${_('Google Analytics code')}:</label> + <label for="ga_code">${_('Analytics HTML block')}:</label> </div> <div class="input"> - ${h.text('ga_code',size=30)} + ${h.textarea('ga_code', cols=80, rows=10)} + <span class="help-block">${_('HTML with JavaScript for web analytics systems like Google Analytics or Piwik. This will be added at the bottom of every page.')}</span> </div> </div>
--- a/kallithea/templates/base/root.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/base/root.html Mon Aug 18 21:04:36 2014 +0200 @@ -22,21 +22,6 @@ ${self.css()} - %if c.ga_code: - <!-- Analytics --> - <script type="text/javascript"> - var _gaq = _gaq || []; - _gaq.push(['_setAccount', '${c.ga_code}']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - </script> - %endif - ## JAVASCRIPT ## <%def name="js()"> <script type="text/javascript"> @@ -149,5 +134,9 @@ <![endif]--> ${next.body()} + + %if c.ga_code: + ${h.literal(c.ga_code)} + %endif </body> </html>