Skip to content

Commit

Permalink
Merge pull request woocommerce#9 from matt-h/master
Browse files Browse the repository at this point in the history
add new option to enable Display Advertising option for Google Analytics
  • Loading branch information
coenjacobs committed Feb 17, 2014
2 parents bb66329 + fb37ee8 commit 42b0ea6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions includes/class-wc-google-analytics-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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);
})();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
})();
";
Expand Down

0 comments on commit 42b0ea6

Please sign in to comment.