We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12043
    • 10 Posts
    I recently switched to Revo (last night) and I am having trouble finding a Google Analytics plugin. I refresh my pages so often when developing that I really need a plugin (like in Evo) that comments out the analytics code/tag when logged into the manager. Am I simply missing it or does it not exist?
      • 4971
      • 964 Posts
      I usually create a TV that I put in my templates
      and in the TV I either place the GA code or a chunks that
      has on it the GA code.

      That way it is always in all the pages, without needing a plugin.
        Website: www.mercologia.com
        MODX Revo Tutorials:  www.modxperience.com

        MODX Professional Partner
        • 364
        • 32 Posts
        I’ve been looking into wanting this as well. As my testing and dev makes my GA numbers way off. in my searching the forums http://modxcms.com/forums/index.php/topic,61561.0.html has been the best thing i’ve seen in my search. I’m going to go try it out now and see if it does the trick for me. I just call a chunk in my template for my GA code. I do miss the evo GA plugin.

        -edit
        Here is what i used and is working for me. i had a chunk called GAnalytics with my ga code. In my template i had [[!Get_Analytics]] I figure this way i could always tweak with my GA code and not have to worry about messing up the snippet. perhaps less over head when logged in this way?
        <?php
        // snippet
        // Gets the analytics if the person is not logged in
        // Must call un-cached.
        // [[!Get_Analytics]]
        	
        	$output = '';
        $viewer_logged_in = false;
        	
        	$viewer = $modx->user;
        	if( $viewer->get('id') != null )
        		$viewer_logged_in = true;
        	if($viewer_logged_in == false)
        	{
        		$output = '[[$GAnalytics]]';
        	}
        	else
        	{
        		$output = 'You Are Logged In';
        	}
        	
        	return $output;

          • 4971
          • 964 Posts
          Good idea, even though I think there is a parameter that can be used
          in the GA code to not count the hits and clicks that come from your
          IP/machine. I dont have that info handy, I will try to search for it
          when I have time...
            Website: www.mercologia.com
            MODX Revo Tutorials:  www.modxperience.com

            MODX Professional Partner
            • 12043
            • 10 Posts
            This is PERFECT! Thank you SOOOOO much! Sorry I didn’t respond earlier, things are crazy, but thanks so much! Maybe you should submit this as a snippet to the Extras? I’m going to edit the snippet so a parameter, the account number, can be passed to the snippet and inserted into standard analytics code. No need for the chunk that way.
              • 12043
              • 10 Posts
              Actually, maybe I can alter the Evo plugin and bring it in line with Revo. It’s pretty simple and a good project to learn on... I’m proficient in ModX, just not coding plugins and snippets.
                • 3749
                • 24,544 Posts
                This single-line snippet should do it if your Manager username is admin (change the string if not):


                <?php
                return $modx->user->get('username') == 'admin' ?  'You are logged in.'  :  $modx->getChunk('GAnalytics') ;


                It’s a little shorter and faster, and will still work if there are users logging in to the front end.

                If you have multiple administrators, this should work:

                <?php
                return $modx->user->isMember('Administrator') ?  'You are logged in.'  :  $modx->getChunk('GAnalytics') ;
                

                  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
                  • 12028
                  • 152 Posts
                  @BobRay:

                  As the way I see it, your solution are the most elegant and functional!

                  But it seems to be that it only works in the standard context (web) - if I am in a installation with multiply contexts (and logged in as at admin in the manager), it’s output the Analytics code - or are I’m missing something?
                    - A small step for mankind, so why not take two...

                    Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!
                    • 3749
                    • 24,544 Posts
                    Quote from: Henrik at May 14, 2011, 01:55 PM

                    @BobRay:

                    As the way I see it, your solution are the most elegant and functional!

                    But it seems to be that it only works in the standard context (web) - if I am in a installation with multiply contexts (and logged in as at admin in the manager), it’s output the Analytics code - or are I’m missing something?
                    It should work in any context as long as your are either logged in in the front end as the admin or logged in in the Manager as the admin and previewing from there.

                    If you want to turn off GA when *anyone* is logged in to any context, you’d do this:

                    return $modx->user->hasSessionContext($modx->context->get('key')) ?  'You are logged in.'  :  $modx->getChunk('GAnalytics') ;


                      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
                      • 12028
                      • 152 Posts
                      @BobRay: Thanks for your reply!
                      I don’t get it: I have a installation on Revo 2.10 RC 4 where there are 4 contexts - all are different domains.tld. All of them have the same context settings in the Access Permissions tab:
                      Usergroup: (anonymous) - Authority: 9999 - Access policy: Load only
                      Usergroup: Administrator - Authority: 0 - Access policy: Administrator

                      I have not messed with other permission settings, and I am the only with access to the manager.

                      But still the snippet only works on the default context (web), do you - or anybody else - have any clues on this?
                        - A small step for mankind, so why not take two...

                        Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!