How to disable tracking code in edit mode?

Permalink 1 user found helpful
Hi there,

I need to hide the tracking code (setting through dashboard -> Sitewide Settings) when a page is in edit mode. Because this code runs every time when i edit my page and increase the page hits rapidly.

 
Mainio replied on at Permalink Reply
Mainio
1. Copy /concrete/elements/footer_required.php to /elements/footer_required.php
2. Open the copied file for editing
3. There you see this:
echo Config::get('SITE_TRACKING_CODE');

4. Wrap it around if clause:
if (!$c->isEditMode()) {
   echo Config::get('SITE_TRACKING_CODE');
}


If it gives you $c is not defined, at the top of that file, add this:
global $c;



Br,
Antti / Mainio
kjosepharistotil replied on at Permalink Reply
Thanks for your quick reply... But I tried that and looks not working in my site...
Mainio replied on at Permalink Reply
Mainio
Well that disables it for EDIT mode which means that you have clicked the EDIT button from a page after logging in.

If you want to disable the code always if you're logged in, just add this to the footer_required.php:
if (!$u->isLoggedIn()) {
   echo Config::get('SITE_TRACKING_CODE');
}


And again, if you get $u is not defined, just add this to the top of the file:
global $u;


Antti / Mainio
potter4991 replied on at Permalink Reply
This use to work for me on my site (saved in elements/footer_required.php)

<?php 
    $u = new User(); 
    if (!$u->isRegistered()) { 
    echo Config::get('SITE_TRACKING_CODE');
} ?>


Now, with Concrete 5.5.1 it just removes the edit bar.

Help!?

Ollie
fastcrash replied on at Permalink Reply
fastcrash
everyone have his own style, maybe this :)
$path = explode("/", $_SERVER['PHP_SELF']);
if ($path[2] != 'dashboard' || !$c->isEditMode()) { //exclude dashboard hits and edit mode
   echo Config::get('SITE_TRACKING_CODE');
}


sometimes dashboard get tracked too


fast-cgi
potter4991 replied on at Permalink Reply
Turns out this was the fix (added to both footer_required and header_required)

<?php 
$u = new User();
$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) /**/ && !$u->isRegistered() || $_trackingCodePosition === 'bottom') /**/ && !$u->isRegistered() {
   echo Config::get('SITE_TRACKING_CODE');
}
print $this->controller->outputFooterItems();
?>


Kudos to my mate Lc for the fix!