How do I disable tracking for editable users (canAdminPage?)

Permalink
How do I access the old canAdminPage() method for the current page in order to disable tracking codes? I don't want admin users triggering google analytics hits as they navigate around my site.
I found out how to do this in 5.6, but the page properties have since changed and I've searched for a couple of hours and not found an answer for 5.7

 
admin replied on at Permalink Reply
Nobody have any ideas?
Mainio replied on at Permalink Reply
Mainio
It should work the same way as it has before if you're calling the method for the permissions object (or actually it's permission checker in 5.7). I don't understand what you refer to by saying "the page properties have since changed". I don't think the method names for the permission checker have changed.

If you posted your code in the topic, it might help to see your problem. Also, if you see some error messages, post them too.
admin replied on at Permalink Reply
I was using code from this page:http://www.concrete5.org/documentation/how-tos/developers/how-to-hi...

<?php
$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) {
    global $cp;
    if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) {
        echo '<!-- tracking code disabled -->';
    } else {
        echo Config::get('SITE_TRACKING_CODE');
    }
}
print $this->controller->outputFooterItems();
?>


The new footer require code is thus:
<?php
$c = Page::getCurrentPage();
if (is_object($c)) {
    $cp = new Permissions($c);
    Loader::element('page_controls_footer', array('cp' => $cp, 'c' => $c));
}
$_trackingCodePosition = Config::get('concrete.seo.tracking.code_position');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) {
   global $cp;
    if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) {
        echo '<!-- tracking code disabled -->';
    } else {
        echo Config::get('SITE_TRACKING_CODE');
    }
}


But this just returns the tracking code regardless with no errors.
Mainio replied on at Permalink Reply
Mainio
OK, thanks.

Remove this line from the code:
global $cp;


And it should work after that.
malkau replied on at Permalink Reply
malkau
Thanks! The "old way" still works, just need to change:

global $cp;


to:

$cp = new Permissions($c);


Thanks for saving me! How do we get that "How To" page updated?

Cheers
Mainio replied on at Permalink Reply
Mainio
By the way, I think it would be way easier to do it straight in the "footer_required" element call.

Meaning that this should work too in your footer (although have not tested):

<?php
$cp = new Permissions($c);
View::element('footer_required', array('disableTrackingCode' => is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())))
?>
admin replied on at Permalink Reply
Your first solution worked, but I do prefer the second option and having it in the theme, rather than overriding system files.

The second one works, but I replaced view with Loader, since that seems to be how the header works when passing parameters in. I take it that the header required can have the same parameters passed like this?
Mainio replied on at Permalink Reply
Mainio
You should also be able to pass the same parameters as the second argument to the View::element() call. The Loader method is just a synonym / backwards compatibility function for the same thing.

I can see the Loader call is still being used in the core themes as well but its use should be discouraged as it's a legacy method.