You are here

function simplenews_statistics_ga_simplenews_statistics_rewrite_goto_url in Simplenews Statistics 7.2

Same name and namespace in other branches
  1. 7 simplenews_statistics_ga/simplenews_statistics_ga.module \simplenews_statistics_ga_simplenews_statistics_rewrite_goto_url()

Implements hook_simplenews_statistics_rewrite_goto_url().

@todo: implement use of tokens

File

simplenews_statistics_ga/simplenews_statistics_ga.module, line 41
Main simplenews statistics Google Analytics file.

Code

function simplenews_statistics_ga_simplenews_statistics_rewrite_goto_url(&$path, &$options, $snid, $nid) {
  $ga_account = variable_get('googleanalytics_account', 'UA-');
  if (module_exists('googleanalytics') && !empty($ga_account) && $ga_account != 'UA-') {
    $campaign = variable_get('simplenews_analytics_utm_campaign', '!newsletter_title');
    if ($campaign == '!newsletter_title') {
      $node = node_load($nid);
      $campaign = $node->title;
    }
    if (variable_get('simplenews_statistics_ga_use_hash', 0)) {

      // We shouldn't be using fragment like this, but Google Analytics requires
      // it like this if we have set the fragment option
      // This might corrupt URL's already using the fragment...
      if (!empty($options['fragment'])) {
        $options['fragment'] .= '&';
      }
      $options['fragment'] .= 'utm_source=' . drupal_encode_path(variable_get('simplenews_analytics_utm_source', 'newsletter'));
      $options['fragment'] .= '&utm_medium=' . drupal_encode_path(variable_get('simplenews_analytics_utm_medium', 'email'));
      $options['fragment'] .= '&utm_campaign=' . drupal_encode_path($campaign);
    }
    else {
      $options['query']['utm_source'] = drupal_encode_path(variable_get('simplenews_analytics_utm_source', 'newsletter'));
      $options['query']['utm_medium'] = drupal_encode_path(variable_get('simplenews_analytics_utm_medium', 'email'));
      $options['query']['utm_campaign'] = drupal_encode_path($campaign);
    }
  }
}