Site icon Alchemista

Hide Google Analytics code on concrete5

concrete5 is great CMS. You never have to go back-and-forth admin panel and front panel to see the result.

But this has one down-time, Google Analytic may produce the wrong report.

So I came up with the solution.

.

How to not to print Google Analytics code when Editable Users visited your concrete5 site

Usually, you don’t want to count the users who has toolbar on top. After logging into concrete5, and if you see the toolbar, that means you are associated editor for the site. You don’t want to count those people onto Google Analytics.

  1. Create a blank text file – /elements/footer_required.php
  2. Paste the following codes onto the text file and then save & upload it onto your server.
<?php 
global $cp;
if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) {
    echo '<!-- tracking code disabled -->';
    } else {
    echo Config::get('SITE_TRACKING_CODE');
    }
?>

The code was tested on concrete5.4.1
.
.

If you do so, “Tracking Code” under “Sidewide Setting” of concrete5 dashcoard WILL NOT be printed onto the HTML source if you are editable user.

.

##

Exit mobile version