@@ -289,6 +289,23 @@ def test_get_portal_latlong(self):
289289        obs ._get_portal (self .conf )
290290        self .assertEqual (obs .stats_map_center_longitude , - 105.24827 )
291291
292+     def  test_get_tracking (self ):
293+         obs  =  ConfigurationManager ()
294+ 
295+         # test for multi line content 
296+         self .assertTrue (len (obs .tracking_js_code ) >  520 )
297+         self .assertIn ("['setTrackerUrl'" , obs .tracking_js_code )
298+ 
299+         # test that None is returned, if JS_CODE in config file, but not set 
300+         self .conf .set ('user_tracking' , 'JS_CODE' , "" )
301+         obs ._get_tracking (self .conf )
302+         self .assertEqual (obs .tracking_js_code , None )
303+ 
304+         # test that if JS_CODE is not in config file, result in None 
305+         self .conf .remove_option ('user_tracking' , 'JS_CODE' )
306+         obs ._get_tracking (self .conf )
307+         self .assertEqual (obs .tracking_js_code , None )
308+ 
292309
293310CONF  =  """ 
294311# ------------------------------ Main settings -------------------------------- 
@@ -471,6 +488,25 @@ def test_get_portal_latlong(self):
471488
472489# ----------------------------- iframes settings --------------------------- 
473490[iframe] 
491+ # ----------------------------- User tracking Settings --------------------- 
492+ [user_tracking] 
493+ # You might want to track user on your Qiita instance. You can here inject 
494+ # JavaScript code to the sitebase.html template, which means it will be added 
495+ # to basically every page of Qiita. 
496+ JS_CODE = <!-- Matomo --><script>var _paq = window._paq = window._paq || []; 
497+   /* tracker methods like "setCustomDimension" should be called before 
498+      "trackPageView" */ 
499+   _paq.push(['trackPageView']);_paq.push(['enableLinkTracking']); 
500+   (function() {var u="https://piwik.cebitec.uni-bielefeld.de/";_ 
501+   paq.push(['setTrackerUrl', u+'matomo.php']);_ 
502+   paq.push(['setSiteId', '21']); 
503+   var d=document, g=d.createElement('script'), s=d.getElementsByTagName( 
504+     'script')[0]; 
505+   g.async=true; 
506+   g.src=u+'matomo.js'; 
507+   s.parentNode.insertBefore(g,s);})(); 
508+   </script><!-- End Matomo Code --> 
509+ 
474510""" 
475511
476512if  __name__  ==  '__main__' :
0 commit comments