function googleanalytics_update_6300 in Google Analytics 6.3
Same name and namespace in other branches
- 6.4 googleanalytics.install \googleanalytics_update_6300()
- 7.2 googleanalytics.install \googleanalytics_update_6300()
- 7 googleanalytics.install \googleanalytics_update_6300()
Try to update Google Analytics custom code snippet to async version.
File
- ./
googleanalytics.install, line 294 - Installation file for Google Analytics module.
Code
function googleanalytics_update_6300() {
$ret = array();
// TODO: Backup synchronous code snippets. Remove variables in D8.
variable_set('googleanalytics_codesnippet_before_backup_6300', variable_get('googleanalytics_codesnippet_before', ''));
variable_set('googleanalytics_codesnippet_after_backup_6300', variable_get('googleanalytics_codesnippet_after', ''));
// Upgrade of BEFORE code snippet.
$code_before = variable_get('googleanalytics_codesnippet_before', '');
if (!empty($code_before)) {
// No value, e.g. _setLocalRemoteServerMode()
$code_before = preg_replace('/(.*)pageTracker\\.(\\w+)\\(\\);(.*)/i', '$1_gaq.push(["$2"]);$3', $code_before);
// One value, e.g. _setCookiePath()
$code_before = preg_replace('/(.*)pageTracker\\.(\\w+)\\(("|\'?)(\\w+)("|\'?)\\);(.*)/i', '$1_gaq.push(["$2", $3$4$5]);$6', $code_before);
// Multiple values e.g. _trackEvent()
$code_before = preg_replace('/(.*)pageTracker\\.(\\w+)\\((.*)\\);(.*)/i', '$1_gaq.push(["$2", $3]);$4', $code_before);
variable_set('googleanalytics_codesnippet_before', $code_before);
$ret[] = array(
'success' => TRUE,
'query' => 'Upgraded custom "before" code snippet.',
);
drupal_set_message(db_prefix_tables("<strong>Attempted</strong> to upgrade Google Analytics custom 'before' code snippet. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_6300'. Please consult Google's <a href='https://developers.google.com/analytics/devguides/collection/gajs/'>Asynchronous Tracking Usage Guide</a> if the upgrade was successfully."), 'warning');
}
// Upgrade of AFTER code snippet.
// We cannot update this code snippet automatically. Show message that the upgrade has been skipped.
$code_after = variable_get('googleanalytics_codesnippet_after', '');
if (!empty($code_after)) {
$ret[] = array(
'success' => TRUE,
'query' => 'Skipped custom "after" code snippet.',
);
drupal_set_message(db_prefix_tables("Automatic upgrade of Google Analytics custom 'after' code snippet has been skipped. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_after_backup_6300'. You need to manually upgrade the custom 'after' code snippet."), 'error');
}
return $ret;
}