Currently I'm tracking pageviews on my joomla website with Google Tag Manager. But I want to analyze in Google Analytics how my registered users use my website and how guest use it. This can be done with a 'custom dimension'.

What I've done so far is setting a cookie with javascript using Google Tag Manager. This event is triggered on a certain page, only visible for registered users. It works but it's not a great solution because a registered user can be visiting all kinds of pages. The user does not even have to visit the page triggering the setting of the cookie.

I'm wondering if it would be better to make Joomla set this cookie when a user is logged in, instead of using tag manager for it.

Something like:

$cookieName = "internal";    
if ( ( (JFactory::getUser()->guest) != 1 ) && ( $app->input->cookie->get($cookieName) != "true" ) ){
          $cookieValue = "true";
          $lifetime = "2592000"; //a month in seconds
          $app = JFactory::getApplication();
          $app->input->cookie->set($cookieName, $cookieValue, time() + $lifetime, $app->get('cookie_path', '/'), $app->get('cookie_domain'), $app->isSSLConnection());

Is this a good approach or are there other, better ways? Should I create a small plugin for it? Add it to the template?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.