summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Glastra2011-11-17 15:52:07 (GMT)
committer Matthias Glastra2011-11-17 16:09:07 (GMT)
commit6865dfc6de0169ca4e4b2bbaba573c886e493b75 (patch)
tree9ee01197732f0d849050c0c41e59b35c5bc30c32
parentc33ad4f2a08bd07a43af918501ccbef32c14e93d (diff)
Issue #1062132 by jamiecuthill | iler: Added Enable click tracking and Google Analytics support.
Adding Google Analytics and Social Tracking support.
-rw-r--r--addthis.test18
-rw-r--r--classes/AddThis.php16
-rw-r--r--includes/addthis.admin.inc16
3 files changed, 50 insertions, 0 deletions
diff --git a/addthis.test b/addthis.test
index 826e22a..a3a70f6 100644
--- a/addthis.test
+++ b/addthis.test
@@ -151,6 +151,10 @@ class AddThisFunctionalityTestCase extends DrupalWebTestCase {
$edit[AddThis::COMPLIANT_508_KEY] = TRUE;
$edit[AddThis::CLICKBACK_TRACKING_ENABLED_KEY] = TRUE;
+
+ $edit[AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY] = TRUE;
+
+ $edit[AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY] = TRUE;
$edit[AddThis::ADDRESSBOOK_ENABLED_KEY] = TRUE;
@@ -203,6 +207,10 @@ class AddThisFunctionalityTestCase extends DrupalWebTestCase {
$this->addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved();
+ $this->addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved();
+
+ $this->addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved();
+
$this->addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved();
$this->addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved();
@@ -256,6 +264,16 @@ class AddThisFunctionalityTestCase extends DrupalWebTestCase {
'AddThis clickback tracking enabled setting should be able to be saved.');
}
+ private function addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved() {
+ $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
+ 'AddThis Google Analytics tracking enabled setting should be able to be saved.');
+ }
+
+ private function addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved() {
+ $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
+ 'AddThis Google Analytics social tracking enabled setting should be able to be saved.');
+ }
+
private function addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved() {
$this->assertFieldChecked('edit-addthis-click-to-open-compact-menu-enabled',
'AddThis click to open compact menu setting should be able to be saved.');
diff --git a/classes/AddThis.php b/classes/AddThis.php
index 0c8e185..0ed3958 100644
--- a/classes/AddThis.php
+++ b/classes/AddThis.php
@@ -33,6 +33,8 @@ class AddThis {
const CUSTOM_CONFIGURATION_CODE_KEY = 'addthis_custom_configuration_code';
const ENABLED_SERVICES_KEY = 'addthis_enabled_services';
const FACEBOOK_LIKE_ENABLED_KEY = 'addthis_facebook_like_enabled';
+ const GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY = 'addthis_google_analytics_tracking_enabled';
+ const GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY = 'addthis_google_analytics_social_tracking_enabled';
const GOOGLE_PLUS_ONE_ENABLED_KEY = 'addthis_google_plus_one_enabled';
const LARGE_ICONS_ENABLED_KEY = 'addthis_large_icons_enabled';
const NUMBER_OF_PREFERRED_SERVICES_KEY = 'addthis_number_of_preferred_services';
@@ -251,6 +253,12 @@ class AddThis {
'ui_use_addressbook' => $this->isAddressbookEnabled(),
'ui_language' => $language->language
);
+ if (module_exists('googleanalytics')) {
+ if ($this->isGoogleAnalyticsTrackingEnabled()) {
+ $configuration['data_ga_property'] = variable_get('googleanalytics_account', '');
+ $configuration['data_ga_social'] = $this->isGoogleAnalyticsSocialTrackingEnabled();
+ }
+ }
// @todo provide hook to alter the default configuration.
$javascript = 'var addthis_config = ' . drupal_json_encode($configuration);
@@ -340,6 +348,14 @@ class AddThis {
public function isAddressbookEnabled() {
return (boolean) variable_get(self::ADDRESSBOOK_ENABLED_KEY, FALSE);
}
+
+ public function isGoogleAnalyticsTrackingEnabled() {
+ return (boolean) variable_get(self::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY, FALSE);
+ }
+
+ public function isGoogleAnalyticsSocialTrackingEnabled() {
+ return (boolean) variable_get(self::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY, FALSE);
+ }
public function getAddThisAttributesMarkup($entity) {
if (is_object($entity)) {
diff --git a/includes/addthis.admin.inc b/includes/addthis.admin.inc
index 814aa61..cab23ec 100644
--- a/includes/addthis.admin.inc
+++ b/includes/addthis.admin.inc
@@ -113,6 +113,22 @@ function addthis_admin_settings_form($form_state) {
'#default_value' => AddThis::getInstance()->isClickbackTrackingEnabled(),
'#required' => FALSE,
);
+ if (module_exists('googleanalytics') && variable_get('googleanalytics_account', '') !== '') {
+ $form['data_tracking_fieldset'][AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Track with Google Analytics'),
+ '#description' => 'Check to track shares in your Google Analytics account reports (<a href="http://www.addthis.com/help/google-analytics-integration">more info</a>). Always global.',
+ '#default_value' => AddThis::getInstance()->isGoogleAnalyticsTrackingEnabled(),
+ '#required' => FALSE,
+ );
+ $form['data_tracking_fieldset'][AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Track with Google Analytics social'),
+ '#description' => 'Check to track shares in the new Google Analytics social interaction reports (<a href="http://www.addthis.com/help/google-analytics-integration#social">more info</a>). Always global.',
+ '#default_value' => AddThis::getInstance()->isGoogleAnalyticsSocialTrackingEnabled(),
+ '#required' => FALSE,
+ );
+ }
$form['email_settings_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Email settings'),