We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26401
    • 247 Posts
    I’m trying to get an analytics thing going through the plugin, and I don’t want it to render when the manager is logged in.
    I’m using the event, OnWebPagePrerender
    and $modx->userLoggedIn(); is not returning anything, do you know what I should use?
      • 26401
      • 247 Posts
      anyway, this is what I have sofar if anyone is interested
      you will need to specify ’code’ in properties
      <?php
      /* Handle event */
      if ($modx->event->name === 'OnWebPagePrerender') {
        $jscode = "<script type='text/javascript'>
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '".$scriptProperties['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>
      </html>" ;
       $output = &$modx->resource->_output;
        $modx->resource->_output= str_replace("</html>",$jscode,$output);
      }


      edit-- fixed a small typo in code that made it not work
        • 3749
        • 24,544 Posts
        Is user logged in in the current context:
        $isLoggedIn = $modx->user->hasSessionContext($modx->context->get('key'));
        

        Is user logged in in the web context:

        $isLoggedIn = $modx->user->hasSessionContext('web');
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 26401
          • 247 Posts
          hmmm, it’s not working for me.
            • 3749
            • 24,544 Posts
            Quote from: daspoda at Oct 11, 2010, 02:14 PM

            hmmm, it’s not working for me.


            It works for me. Are you previewing from the Manager? That will throw things off.

            You may also have to flush permissions and sessions and clear the site/browser casches after making a change.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting