You are here

function addthis_footer in AddThis 6.3

Implements hook_footer().

Google Analytics integration needs custom JavaScript that has to run after the GA tracking object has been initialized.

File

./addthis.module, line 349
Provides integration with the AddThis.com bookmarking & sharing service.

Code

function addthis_footer($main = 0) {
  if ($addthis_counter = addthis_add_default_js(TRUE)) {

    // If javascript caching is enabled and the private file system is not being
    // used, go ahead and load the cached file.
    if (variable_get('addthis_cache_js', 0) && variable_get('file_downloads', 1) == 1 && ($source = addthis_cache_js('http://s7.addthis.com/js/250/addthis_widget.js'))) {
      $output = "<script type='text/javascript' src='" . base_path() . $source . "'></script>";
    }
    else {

      // Otherwise, load the external javascript using a protocol-independent
      // URL.
      $output = "<script type='text/javascript' src='//s7.addthis.com/js/250/addthis_widget.js'></script>";
    }

    // If Google Analytics present, pass the pageTracker object to the
    // addthis_config javascript settings object.
    $config = variable_get('addthis_config', array());
    if (!empty($config['data_ga_tracker'])) {

      // Assume "pageTracker" is the name of the GA tracking object.
      // TODO: Make this configurable in the UI.
      $ga_tracker_name = variable_get('addthis_ga_tracker_name', 'pageTracker');
      drupal_add_js('if (typeof ' . $ga_tracker_name . ' != "undefined") {addthis_config.data_ga_tracker = ' . $ga_tracker_name . ';}', 'inline', 'footer');
    }
    return $output;
  }
}