This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

If you want to include some kind of tracking code in your pages (like Google Analytics), you can use the Tracking Code setting in concrete 5's dashboard.

If you didn't already know, to make the tracking code appear in all your pages, via the dashboard setting, you need to have this code in your template:

 Loader::element('footer_required');

However, that way, the tracking code is shown to everyone, even logged in users.

To make sure it only gets displayed to users not logged in or not of a specific user group, you cannot use that dashboard setting. You need to directly edit your template's php file.

If you're designing your own theme this will be easier but if not you need to go into your concrete5 themes directory, find your theme and make this edit on all the files of the templates you want the code to appear in (like view.php and/or others).

Open the .php file and where you have the footer (or in any other part of the page where you want the tracking code to appear) insert this php code:

<?php
    $u = new User();
    if (!$u->isLoggedIn()) {
?>
        <!-- Insert your tracking code here -->
<?php
}
?>

What that means is that the tracking code will only be included in the page if the user is not logged in.

But what if you have a group of, say, clients? And you do want the tracking code to be included when they are logged in. In that case, you could use this code instead:

<?php
$u = new User();
$g = Group::getByName("clients"); 
if(!$u->isLoggedIn() || $user->inGroup($g)) {
?>
        <!-- Insert your tracking code here -->
<?php
}
?>

It will include the tracking code if the user is not logged in or if the user belongs to the group with the name "clients". Change the code to suit your needs.

Remember that you need to include the conditional code in every page template, if you want the tracking to be in all pages. Also, if you use this method you don't have to use that dashboard setting.

I hope this has helped you. Good luck in creating your concrete5 website!

Loading Conversation