Permalink
Browse files

Merge pull request #9 from matt-h/master

add new option to enable Display Advertising option for Google Analytics
  • Loading branch information...
2 parents bb66329 + fb37ee8 commit 42b0ea622c3cfb088d8a7e89d32d0de4def58ad7 @coenjacobs coenjacobs committed Feb 17, 2014
Showing with 20 additions and 2 deletions.
  1. +20 −2 includes/class-wc-google-analytics-integration.php
@@ -29,6 +29,7 @@ public function __construct() {
$this->ga_id = $this->get_option( 'ga_id' );
$this->ga_set_domain_name = $this->get_option( 'ga_set_domain_name' );
$this->ga_standard_tracking_enabled = $this->get_option( 'ga_standard_tracking_enabled' );
+ $this->ga_support_display_advertising = $this->get_option( 'ga_support_display_advertising' );
$this->ga_ecommerce_tracking_enabled = $this->get_option( 'ga_ecommerce_tracking_enabled' );
$this->ga_event_tracking_enabled = $this->get_option( 'ga_event_tracking_enabled' );
@@ -73,6 +74,12 @@ function init_form_fields() {
'checkboxgroup' => 'start',
'default' => get_option('woocommerce_ga_standard_tracking_enabled') ? get_option('woocommerce_ga_standard_tracking_enabled') : 'no' // Backwards compat
),
+ 'ga_support_display_advertising' => array(
+ 'label' => __( 'Set the Google analytics code to support Display Advertising. <a href="https://support.google.com/analytics/answer/2700409" target="_blank">Read More About Display Advertising</a>', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'checkboxgroup' => '',
+ 'default' => get_option('woocommerce_ga_support_display_advertising') ? get_option('woocommerce_ga_support_display_advertising') : 'no' // Backwards compat
+ ),
'ga_ecommerce_tracking_enabled' => array(
'label' => __( 'Add eCommerce tracking code to the thankyou page', 'woocommerce' ),
'type' => 'checkbox',
@@ -115,6 +122,12 @@ function google_tracking_code() {
$username = __( 'Guest', 'woocommerce' );
}
+ if ( $this->ga_support_display_advertising == 'yes' )
+ $ga_url = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'";
+ else
+ $ga_url = "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'";
+
+
if ( ! empty( $this->ga_set_domain_name ) )
$set_domain_name = "['_setDomainName', '" . esc_js( $this->ga_set_domain_name ) . "'],\n";
else
@@ -131,7 +144,7 @@ function google_tracking_code() {
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ ga.src = ".$ga_url.";
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@@ -173,6 +186,11 @@ function ecommerce_tracking_code( $order_id ) {
$username = __( 'Guest', 'woocommerce' );
}
+ if ( $this->ga_support_display_advertising == 'yes' )
+ $ga_url = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'";
+ else
+ $ga_url = "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'";
+
if ( ! empty( $this->ga_set_domain_name ) )
$set_domain_name = "['_setDomainName', '" . esc_js( $this->ga_set_domain_name ) . "'],";
else
@@ -235,7 +253,7 @@ function ecommerce_tracking_code( $order_id ) {
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ ga.src = ".$ga_url.";
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
";

0 comments on commit 42b0ea6

Please sign in to comment.