concrete5: how to hide tracking code for editable users (post 5.5.x)


In order to receive the acurate Google Analytics visitor’s data, you want to avoid tracking the access when the site admin visits a concrete5 site.

This is how to hide the Google Analytics tracking code when the users who has the editing permission or admin visited your concrete5 site.

This method only works with concrete5.5.x and later.

1. Create a blank text file /elements/footer_required.php

2. And paste the following text file

<?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();

?>

3. Copy /concrete/elements/header_required.php onto /elements/header_required.php

4. Replace where the following code (towards the end)

$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && $_trackingCodePosition === 'top') {
	echo Config::get('SITE_TRACKING_CODE');
}

onto this

$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && $_trackingCodePosition === 'top') {
	if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) {
		echo '<!-- tracking code disabled -->';
	} else {
		echo Config::get('SITE_TRACKING_CODE');
	}
}

Now Google Analytics code will no longer be printed on your concrete5 site when the admin/webmaster visits