Hi everyone!,
The archivist responsible for our AtoM has received in Google Analytics a warning on GA type of key change, UA- to G-, that will happen next year, so she contacted the IT department to apply this change worried on statistics functionality loss...
To reply to her request I fiddled with config/app and that didn't work. Then searching a bit in github, though I never programmed in PHP, nor I know what am I doing in AtoM!, this hack seams to work:
- in config/app.yml a new property to prevent writing of template _footer GA block and write new GA block next to <head> tag
# Google Analitycs:
# Set a GA property API key to track page view hits.
# E.g.: UA-1234567-89
google_analytics_api_key:
# hack for v4 keys -> ga block on <head>
google_analytics_api_key_4: G-XXXXXXXX
- apps/qubit/config/qubitConfiguration.class.php , function responseFilterContent
public function responseFilterContent(sfEvent $event, $content)
{
ProjectConfiguration::getActive()->loadHelpers('Javascript');
$gaKey = sfConfig::get('app_google_analytics_api_key_4', '');
if (!empty($gaKey)) {
$newHead = '<head>'.PHP_EOL;
$newHead .= '<!-- Global site tag (gtag.js) - Google Analytics -->'.PHP_EOL;
$newHead .= '<script async src="
https://www.googletagmanager.com/gtag/js?id=gaKey"></script>'.PHP_EOL.'<script>'.PHP_EOL;
$newHead .= 'window.dataLayer = window.dataLayer || [];'.PHP_EOL;
$newHead .= 'function gtag(){dataLayer.push(arguments);}'.PHP_EOL;
$newHead .= "gtag('js', new Date());".PHP_EOL.PHP_EOL;
$newHead .= "gtag('config', 'gaKey');".PHP_EOL."</script>";
$newHead = str_ireplace('gaKey', $gaKey, $newHead);
return str_ireplace('</head>', javascript_tag('jQuery.extend(Qubit, '.json_encode(array('relativeUrlRoot' => sfContext::getInstance()->request->getRelativeUrlRoot())).');').'</head>', str_ireplace('<head>', $newHead, $content));
}
return str_ireplace('</head>', javascript_tag('jQuery.extend(Qubit, '.json_encode(array('relativeUrlRoot' => sfContext::getInstance()->request->getRelativeUrlRoot())).');').'</head>', $content);
}
We are using AtoM 2.6.2 and waiting to upgrade to 2.7.
Is there a way to properly use GA 4 G-XXXXXXXX in version 2.6.2? Will it be implemented in version 2.7?
Thanks