Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, Facebook and more - Version 1.4.17

Version Description

  • Info: Tested up to WP 5.1
Download this release

Release Info

Developer alekv
Plugin Icon 128x128 Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, Facebook and more
Version 1.4.17
Comparing to
See all releases

Code changes from version 1.3.6 to 1.4.17

Files changed (4) hide show
  1. includes/class-db-upgrade.php +65 -0
  2. includes/rating.php +0 -47
  3. readme.txt +60 -24
  4. wgact.php +385 -122
includes/class-db-upgrade.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DB upgrade function
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly
8
+ }
9
+
10
+ class WGACT_DB_Upgrade {
11
+
12
+ protected $options_db_name = 'wgact_plugin_options';
13
+
14
+ public function __construct() {
15
+ }
16
+
17
+ public function run_options_db_upgrade() {
18
+
19
+ // determine version and run version specific upgrade function
20
+ // check if options db version zero by looking if the old entries are still there.
21
+ if ( ( get_option( 'wgact_plugin_options_1' ) ) or ( get_option( 'wgact_plugin_options_2' ) ) ) {
22
+ // error_log( 'current db version is zero ' );
23
+ $this->upgrade_options_db_from_zero_to_1_point_zero();
24
+ }
25
+ }
26
+
27
+ public function upgrade_options_db_from_zero_to_1_point_zero() {
28
+
29
+ $option_name_1 = 'wgact_plugin_options_1';
30
+ $option_name_2 = 'wgact_plugin_options_2';
31
+
32
+ // get current options
33
+ // get option 1
34
+ if ( ! ( get_option( $option_name_1 ) ) ) {
35
+ $option_value_1 = "";
36
+ } else {
37
+ $option_value_1_array = get_option( $option_name_1 );
38
+ $option_value_1 = $option_value_1_array['text_string'];
39
+ }
40
+
41
+ // get option 2
42
+ if ( ! ( get_option( $option_name_2 ) ) ) {
43
+ $option_value_2 = "";
44
+ } else {
45
+ $option_value_2_array = get_option( $option_name_2 );
46
+ $option_value_2 = $option_value_2_array['text_string'];
47
+ }
48
+
49
+ // db version place options into new array
50
+ $options_array = array(
51
+ 'conversion_id' => $option_value_1,
52
+ 'conversion_label' => $option_value_2,
53
+ );
54
+
55
+ // store new option array into the options table
56
+ update_option( $this->options_db_name, $options_array );
57
+
58
+ // delete old options
59
+ // only on single site
60
+ // we will run the multisite deletion only during uninstall
61
+ delete_option( $option_name_1 );
62
+ delete_option( $option_name_2 );
63
+
64
+ }
65
+ }
includes/rating.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly
5
- }
6
-
7
- ?>
8
-
9
- <div class="rate">
10
- <div class="rating-stars">
11
- <a href="//wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=1#postform"
12
- data-rating="1" title="" target="_blank">
13
- <span class="dashicons dashicons-star-filled" style="color:#ffb900 !important;"></span></a>
14
- <a href="//wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=2#postform"
15
- data-rating="2" title="" target="_blank">
16
- <span class="dashicons dashicons-star-filled" style="color:#ffb900 !important;"></span></a>
17
- <a href="//wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=3#postform"
18
- data-rating="3" title="" target="_blank">
19
- <span class="dashicons dashicons-star-filled" style="color:#ffb900 !important;"></span></a>
20
- <a href="//wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=4#postform"
21
- data-rating="4" title="" target="_blank">
22
- <span class="dashicons dashicons-star-filled" style="color:#ffb900 !important;"></span></a>
23
- <a href="//wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=5#postform"
24
- data-rating="5" title="" target="_blank">
25
- <span class="dashicons dashicons-star-filled" style="color:#ffb900 !important;"></span></a>
26
- </div>
27
- <input type="hidden" name="rating" id="rating" value="5">
28
- <input type="hidden" name="review_topic_slug" value="woocommerce-google-adwords-conversion-tracking-tag">
29
- <script>
30
- jQuery(document).ready(function ($) {
31
- $('.rating-stars').find('a').hover(
32
- function () {
33
- $(this).nextAll('a').children('span').removeClass('dashicons-star-filled').addClass('dashicons-star-empty');
34
- $(this).prevAll('a').children('span').removeClass('dashicons-star-empty').addClass('dashicons-star-filled');
35
- $(this).children('span').removeClass('dashicons-star-empty').addClass('dashicons-star-filled');
36
- }, function () {
37
- var rating = $('input#rating').val();
38
- if (rating) {
39
- var list = $('.rating-stars a');
40
- list.children('span').removeClass('dashicons-star-filled').addClass('dashicons-star-empty');
41
- list.slice(0, rating).children('span').removeClass('dashicons-star-empty').addClass('dashicons-star-filled');
42
- }
43
- }
44
- );
45
- });
46
- </script>
47
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,47 +1,40 @@
1
  === Plugin Name ===
2
  Contributors: alekv
3
  Donate link: http://www.wolfundbaer.ch/donations/
4
- Tags: woocommerce, woocommerce conversion tracking, google adwords, adwords, conversion, conversion value, conversion tag, conversion pixel, conversion value tracking, conversion tracking, conversion tracking adwords, conversion tracking pixel, conversion tracking script, track conversions, tracking code manager
5
- Requires at least: 3.1
6
- Tested up to: 4.8
7
- Stable tag: 1.3.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Track the dynamic order value in AdWords from WooCommerce
12
 
13
  == Description ==
14
 
15
- This plugin <strong>tracks the value of WooCommerce orders in Google AdWords</strong>. With this you can optimize all your AdWords campaings to achieve maximum efficiency.
16
 
17
  <strong>Highlights</strong>
18
 
19
- * Very accurate by preventing duplicate reporting effectively, excluding admins and shop managers from tracking, and not counting failed payments.
 
20
  * Very easy to install and maintain.
21
 
22
  <strong>Requirements</strong>
23
 
24
  * The payment gateway **must** support on-site payments. If you want to use an off-site payment solution like the free PayPal extension you need to make sure that the visitor is being redirected back to the WooCommerce thankyou page after the successful transaction. Only if the redirection is set up properly and the visitor doesn't stop the redirection, only then the conversion will be counted.
 
25
 
26
  <strong>Other plugins</strong>
27
 
28
- If you like this plugin you might like that one too: https://wordpress.org/plugins/woocommerce-google-dynamic-retargeting-tag/
29
-
30
- <strong>Supported languages</strong>
31
-
32
- * English
33
- * German
34
- * Serbian ( by Adrijana Nikolic http://webhostinggeeks.com )
35
 
36
  == Installation ==
37
 
38
- 1. Upload the WGACT Plugin directory into your `/wp-content/plugins/` directory
39
  2. Activate the plugin through the 'Plugins' menu in WordPress
40
- 3. Get the AdWords conversion ID and the conversion label. You will find both values in the AdWords conversion tracking code.
41
- 4. In the WordPress admin panel go to settings and then into the WGACT Plugin Menu. Please enter the conversion ID and the conversion label into their respective fields.
42
- 5. Delete any other instances of the AdWords tracking code which tracks sales. (You might have several AdWords tracking codes, eg. tracking newsletter applications. Keep those.)
43
- 6. Delete the cache on your server and on your browser.
44
- 7. Check if the AdWords tag is running fine by placing a test order (ideally click on one of your AdWords ads first) and then check with the Google Tag Assistant browser plugin if the tag has been inserted correctly on the thank you page. Bear in mind that the code is only visible if you are not logged in as admin or shop manager. You will have to log out first.
45
 
46
  == Frequently Asked Questions ==
47
 
@@ -50,17 +43,17 @@ If you like this plugin you might like that one too: https://wordpress.org/plugi
50
  1. Log out of the shop.
51
  2. Search for one of your keywords and click on one of your ads.
52
  3. Purchase an item from your shop.
53
- 4. Wait until the conversion shows up in AdWords.
54
 
55
  With the Google Tag Assistant you will also be able to see the tag fired on the thankyou page.
56
 
57
  = I get a fatal error and I am running old versions of WordPress and/or WooCommerce. What can I do? =
58
 
59
- As this is a free plugin we don't support old version of WordPress and WooCommerce. You will have to update your installation.
60
 
61
  = I am using an offsite payment gateway and the conversions are not being tracked. What can I do? =
62
 
63
- We don't support if an offsite payment gateway is in use. The reason is that those cases can be complex and time consuming. We don't want to cover this for a free plugin. We do not recommend offsite payment gateways anyway. A visitor can stop the redirection manually which prevents at least some conversions to be tracked. Also offsite payment gateways are generally bad for the conversion rate.
64
 
65
  = Where can I report a bug or suggest improvements? =
66
 
@@ -71,7 +64,50 @@ You can send the link to the front page of your shop too if you think it would b
71
  1. Settings page
72
 
73
  == Changelog ==
74
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  = 1.3.6 =
76
  * New: WordPress 4.8 compatibility update
77
  * Tweak: Minor text tweak.
1
  === Plugin Name ===
2
  Contributors: alekv
3
  Donate link: http://www.wolfundbaer.ch/donations/
4
+ Tags: woocommerce, woocommerce conversion tracking, google adwords, adwords, conversion, conversion value, conversion tag, conversion pixel, conversion value tracking, conversion tracking, conversion tracking adwords, conversion tracking pixel, conversion tracking script, track conversions, tracking code manager, google ads
5
+ Requires at least: 3.7
6
+ Tested up to: 5.1
7
+ Stable tag: 1.4.17
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Track the dynamic order value in Google Ads from WooCommerce
12
 
13
  == Description ==
14
 
15
+ This plugin <strong>tracks the value of WooCommerce orders in Google Ads</strong>. With this you can optimize all your Google Ads campaigns to achieve maximum efficiency.
16
 
17
  <strong>Highlights</strong>
18
 
19
+ * The plugin has been updated with the newest Google Ads conversion tracking script that deals with the new Apple cookie tracking prevention. [Apple Intelligent Tracking Prevention](https://webkit.org/blog/7675/intelligent-tracking-prevention/) and [New Google Ads Conversion Tracking Tag](https://support.google.com/adwords/answer/7521212)
20
+ * Very precise by preventing duplicate reporting effectively, excluding admins and shop managers from tracking, and not counting failed payments.
21
  * Very easy to install and maintain.
22
 
23
  <strong>Requirements</strong>
24
 
25
  * The payment gateway **must** support on-site payments. If you want to use an off-site payment solution like the free PayPal extension you need to make sure that the visitor is being redirected back to the WooCommerce thankyou page after the successful transaction. Only if the redirection is set up properly and the visitor doesn't stop the redirection, only then the conversion will be counted.
26
+ * As this is a free plugin we only support recent versions of WooCommerce, WordPress and PHP. We don't maintain backward compatibility.
27
 
28
  <strong>Other plugins</strong>
29
 
30
+ If you like this plugin you might like that one too: [WooCommerce Google Ads Dynamic Remarketing](https://wordpress.org/plugins/woocommerce-google-dynamic-retargeting-tag/)
 
 
 
 
 
 
31
 
32
  == Installation ==
33
 
34
+ 1. Upload the plugin directory into your plugins directory `/wp-content/plugins/`
35
  2. Activate the plugin through the 'Plugins' menu in WordPress
36
+ 3. Get the Google Ads conversion ID and the conversion label. You will find both values in the Google Ads conversion tracking code. [Get the conversion ID and the conversion label](https://www.youtube.com/watch?v=p9gY3JSrNHU)
37
+ 4. In the WordPress admin panel go to WooCommerce and then into the 'Google Ads Conversion Tracking' menu. Please enter the conversion ID and the conversion label into their respective fields.
 
 
 
38
 
39
  == Frequently Asked Questions ==
40
 
43
  1. Log out of the shop.
44
  2. Search for one of your keywords and click on one of your ads.
45
  3. Purchase an item from your shop.
46
+ 4. Wait up to 48 hours until the conversion shows up in Google Ads.
47
 
48
  With the Google Tag Assistant you will also be able to see the tag fired on the thankyou page.
49
 
50
  = I get a fatal error and I am running old versions of WordPress and/or WooCommerce. What can I do? =
51
 
52
+ As this is a free plugin we don't support old versions of WordPress and WooCommerce. You will have to update your installation.
53
 
54
  = I am using an offsite payment gateway and the conversions are not being tracked. What can I do? =
55
 
56
+ We don't support if an offsite payment gateway is in use. The reason is that those cases can be complex and time consuming to solve. We don't want to cover this for a free plugin. We do not recommend offsite payment gateways anyway. A visitor can stop the redirection manually which prevents at least some conversions to be tracked. Also offsite payment gateways are generally bad for the conversion rate.
57
 
58
  = Where can I report a bug or suggest improvements? =
59
 
64
  1. Settings page
65
 
66
  == Changelog ==
67
+ = 1.4.17 =
68
+ * Info: Tested up to WP 5.1
69
+ = 1.4.16 =
70
+ * Info: Updated a few text strings
71
+ = 1.4.15 =
72
+ * Info: Changing name from AdWords to Google Ads
73
+ = 1.4.14 =
74
+ * Info: Tested up to WC 3.5.3
75
+ = 1.4.13 =
76
+ * Info: Tested up to WC 3.5.2
77
+ = 1.4.12 =
78
+ * Tweak: bumping up the WC version
79
+ = 1.4.11 =
80
+ * Tweak: remove some debug code
81
+ * fix: properly save the order_total_logic option
82
+ = 1.4.10 =
83
+ * Tweak: switched sanitization function to wp_strip_all_tags
84
+ = 1.4.9 =
85
+ * Tweak: Added input validation and sanitization
86
+ * Tweak: Added output escaping
87
+ = 1.4.8 =
88
+ * Tweak: Added discounts into order value calculation
89
+ = 1.4.7 =
90
+ * New: Switched over to the newest version of the AdWords conversion tracking pixel
91
+ = 1.4.6 =
92
+ * Tweak: Disabled minification through Autoptimize
93
+ = 1.4.5 =
94
+ * Tweak: Order ID back in apostrophes
95
+ = 1.4.4 =
96
+ * Tweak: Switched on JavaScript tracking with a fix for the CDATA bug http://core.trac.wordpress.org/ticket/3670
97
+ * Tweak: The correct function is being used to get the currency depending on the WooCommerce version
98
+ * Fix: Added missing </noscript> tag
99
+ = 1.4.3 =
100
+ * Tweak: Remove campaign URL parameter
101
+ = 1.4.2 =
102
+ * Fix: Backward compatibility for $order->get_currency()
103
+ = 1.4.1 =
104
+ * Tweak: Making the plugin PHP 5.4 backwards compatible
105
+ * Fix: Fixing double counting check logic
106
+ = 1.4 =
107
+ * New: Ask kindly for a rating of the plugin
108
+ * New: Add a radio button to use different styles of order total
109
+ * Tweak: Consolidate options into one array
110
+ * Tweak: Code cleanup
111
  = 1.3.6 =
112
  * New: WordPress 4.8 compatibility update
113
  * Tweak: Minor text tweak.
wgact.php CHANGED
@@ -1,15 +1,26 @@
1
  <?php
2
  /**
3
- * Plugin Name: WooCommerce AdWords Conversion Tracking
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/
5
- * Description: Google AdWords dynamic conversion value tracking for WooCommerce.
6
- * Author: Wolf+Bär GmbH
7
  * Author URI: https://wolfundbaer.ch
8
- * Version: 1.3.6
9
  * License: GPLv2 or later
10
  * Text Domain: woocommerce-google-adwords-conversion-tracking-tag
 
 
11
  **/
12
 
 
 
 
 
 
 
 
 
 
13
  if ( ! defined( 'ABSPATH' ) ) {
14
  exit; // Exit if accessed directly
15
  }
@@ -17,8 +28,19 @@ if ( ! defined( 'ABSPATH' ) ) {
17
 
18
  class WGACT {
19
 
 
 
 
20
  public function __construct() {
21
 
 
 
 
 
 
 
 
 
22
  // startup all functions
23
  $this->init();
24
 
@@ -27,6 +49,9 @@ class WGACT {
27
  // startup all functions
28
  public function init() {
29
 
 
 
 
30
  // add the admin options page
31
  add_action( 'admin_menu', array( $this, 'wgact_plugin_admin_add_page' ), 99 );
32
 
@@ -39,11 +64,170 @@ class WGACT {
39
  // Load textdomain
40
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
41
 
42
- // add the Google AdWords tag to the thankyou part of the page within the body tags
43
- add_action( 'woocommerce_thankyou', array( $this, 'GoogleAdWordsTag' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  // Load text domain function
48
  public function load_plugin_textdomain() {
49
  load_plugin_textdomain( 'woocommerce-google-adwords-conversion-tracking-tag', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
@@ -61,9 +245,9 @@ class WGACT {
61
  // add the admin options page
62
  function wgact_plugin_admin_add_page() {
63
  //add_options_page('WGACT Plugin Page', 'WGACT Plugin Menu', 'manage_options', 'wgact', array($this, 'wgact_plugin_options_page'));
64
- add_submenu_page( 'woocommerce', esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), esc_html__( 'AdWords Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), 'manage_options', 'wgact', array(
65
  $this,
66
- 'wgact_plugin_options_page'
67
  ) );
68
  }
69
 
@@ -72,181 +256,260 @@ class WGACT {
72
 
73
  ?>
74
 
75
- <br>
76
- <div style="float: right; padding-right: 20px">
77
- <div style="float:left; margin-right: 10px">Please tell us how much you like the plugin!</div>
78
- <div style="float:left"><?php require( 'includes/rating.php' ); ?></div>
79
- </div>
80
- <div style="width:980px; float: left; margin: 5px">
81
- <div style="float:left; margin: 5px; margin-right:20px; width:750px">
82
- <div style="background: #0073aa; padding: 10px; font-weight: bold; color: white; border-radius: 2px">
83
- <?php esc_html_e( 'Google AdWords Conversion Tracking Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
84
- </div>
85
- <form action="options.php" method="post">
86
- <?php settings_fields( 'wgact_plugin_options' ); ?>
87
  <?php do_settings_sections( 'wgact' ); ?>
88
- <br>
89
- <table class="form-table" style="margin: 10px">
90
- <tr>
91
- <th scope="row" style="white-space: nowrap">
92
- <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>"
93
- class="button button-primary"/>
94
- </th>
95
- </tr>
96
- </table>
97
- </form>
98
-
99
- <br>
100
- <div
101
- style="background: #0073aa; padding: 10px; font-weight: bold; color: white; margin-bottom: 20px; border-radius: 2px">
102
  <span>
103
  <?php esc_html_e( 'Profit Driven Marketing by Wolf+Bär', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
104
  </span>
105
- <span style="float: right;">
106
- <a href="https://wolfundbaer.ch/?utm_source=WGACT&utm_medium=plugin&utm_campaign=WGACT-Plugin"
107
- target="_blank" style="color: white">
108
- <?php esc_html_e( 'Visit us here: https://wolfundbaer.ch', 'woocommerce-google-dynamic-retargeting-tag' ) ?>
109
  </a>
110
  </span>
111
- </div>
112
- </div>
113
- <div style="float: left; margin: 5px">
114
- <a href="https://wordpress.org/plugins/woocommerce-google-dynamic-retargeting-tag/" target="_blank">
115
- <img src="<?php echo( plugins_url( 'images/wgdr-icon-256x256.png', __FILE__ ) ) ?>" width="150px"
116
- height="150px">
117
- </a>
118
- </div>
119
- <div style="float: left; margin: 5px">
120
- <a href="https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/"
121
- target="_blank">
122
- <img src="<?php echo( plugins_url( 'images/wgact-icon-256x256.png', __FILE__ ) ) ?>" width="150px"
123
- height="150px">
124
- </a>
125
- </div>
126
- </div>
127
  <?php
128
  }
129
 
130
 
131
  // add the admin settings and such
132
  function wgact_plugin_admin_init() {
133
- //register_setting( 'plugin_options', 'plugin_options', 'wgact_plugin_options_validate' );
134
- register_setting( 'wgact_plugin_options', 'wgact_plugin_options_1' );
135
- register_setting( 'wgact_plugin_options', 'wgact_plugin_options_2' );
 
 
136
  add_settings_section( 'wgact_plugin_main', esc_html__( 'Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
137
  $this,
138
- 'wgact_plugin_section_text'
139
  ), 'wgact' );
140
- add_settings_field( 'wgact_plugin_text_string_1', esc_html__( 'Conversion ID', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
 
 
141
  $this,
142
- 'wgact_plugin_setting_string_1'
143
  ), 'wgact', 'wgact_plugin_main' );
144
- add_settings_field( 'wgact_plugin_text_string_2', esc_html__( 'Conversion Label', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
 
 
145
  $this,
146
- 'wgact_plugin_setting_string_2'
147
  ), 'wgact', 'wgact_plugin_main' );
148
- }
149
 
150
- function wgact_plugin_section_text() {
151
- //echo '<p>Woocommerce Google AdWords conversion tracking tag</p>';
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
- /*
155
- function wgact_plugin_setting_string_1() {
156
- $options = get_option('wgact_plugin_options_1');
157
- echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
158
  }
159
- */
160
 
161
- function wgact_plugin_setting_string_1() {
162
- $options = get_option( 'wgact_plugin_options_1' );
163
- echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
164
  }
165
 
166
- function wgact_plugin_setting_string_2() {
167
- $options = get_option( 'wgact_plugin_options_2' );
168
- echo "<input id='wgact_plugin_text_string_2' name='wgact_plugin_options_2[text_string]' size='40' type='text' value='{$options['text_string']}' />";
169
  }
170
 
171
- /*
172
- function wgact_plugin_setting_string_3() {
173
- $options = get_option('wgact_plugin_options_3');
174
- echo "<input id='wgact_plugin_text_string_3' name='wgact_plugin_options_3[text_string]' size='40' type='text' value='{$options['text_string']}' />";
 
 
 
 
 
 
 
175
  }
176
- */
177
 
178
  // validate our options
179
  function wgact_plugin_options_validate( $input ) {
180
- $newinput['text_string'] = trim( $input['text_string'] );
181
- if ( ! preg_match( '/^[a-z0-9]{32}$/i', $newinput['text_string'] ) ) {
182
- $newinput['text_string'] = '';
183
- }
184
 
185
- return $newinput;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  }
187
 
188
- public function GoogleAdWordsTag( $order_id ) {
 
 
 
 
 
 
 
 
 
189
 
190
  $conversion_id = $this->get_conversion_id();
191
  $conversion_label = $this->get_conversion_label();
192
 
193
- // get order from URL and evaluate order total
194
- $order = new WC_Order( $order_id );
195
- $order_total = $order->get_total();
196
-
197
- $order_total = apply_filters( 'wgact_conversion_value_filter', $order_total, $order );
198
 
199
- ?>
 
 
 
 
 
 
 
200
 
 
 
 
201
 
202
- <!-- START Google Code for Sales (AdWords) Conversion Page -->
203
  <?php
204
 
205
- // Only run conversion script if the payment has not failed. (has_status('completed') is too restrictive)
206
- // And use the order meta to check if the conversion code has already run for this order ID. If yes, don't run it again.
207
- // Also don't run the pixel if an admin or shop manager is logged in.
208
- if ( ! $order->has_status( 'failed' ) && ( ( get_post_meta( $order_id, '_WGACT_conversion_pixel_fired', true ) != "true" ) ) && ! current_user_can( 'edit_others_pages' ) ) {
209
- ?>
210
 
211
- <div style="display:inline;">
212
- <img height="1" width="1" style="border-style:none;" alt=""
213
- src="//www.googleadservices.com/pagead/conversion/<?php echo $conversion_id; ?>/?value=<?php echo $order_total; ?>&amp;currency_code=<?php echo $order->get_order_currency(); ?>&amp;label=<?php echo $conversion_label; ?>&amp;guid=ON&amp;oid=<?php echo $order_id; ?>&amp;script=0"/>
214
- </div>
215
 
216
 
217
- <?php
218
- // Set the order ID meta after the conversion code has run once.
219
- update_post_meta( $order_id, '_WGACT_conversion_pixel_fired', 'true' );
220
- } else {
221
 
222
- ?>
 
 
223
 
224
- <!-- The AdWords pixel has not been inserted. Possible reasons: -->
225
- <!-- You are logged into WooCommerce as admin or shop manager. -->
226
- <!-- The order payment has failed. -->
227
- <!-- The pixel has already been fired. To prevent double counting the pixel is not being fired again. -->
228
 
229
- <?php
230
- } // end if order status
231
 
232
- ?>
233
 
234
- <!-- END Google Code for Sales (AdWords) Conversion Page -->
235
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  }
237
 
238
  private function get_conversion_id() {
239
- $opt = get_option( 'wgact_plugin_options_1' );
240
- $conversion_id = $opt['text_string'];
241
 
242
  return $conversion_id;
243
  }
244
 
245
- // insert the Google AdWords tag into the page
246
 
247
  private function get_conversion_label() {
248
- $opt = get_option( 'wgact_plugin_options_2' );
249
- $conversion_label = $opt['text_string'];
250
 
251
  return $conversion_label;
252
  }
1
  <?php
2
  /**
3
+ * Plugin Name: WooCommerce Google Ads Conversion Tracking
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/
5
+ * Description: Google Ads dynamic conversion value tracking for WooCommerce.
6
+ * Author: Wolf+Bär Agency
7
  * Author URI: https://wolfundbaer.ch
8
+ * Version: 1.4.17
9
  * License: GPLv2 or later
10
  * Text Domain: woocommerce-google-adwords-conversion-tracking-tag
11
+ * WC requires at least: 2.6.0
12
+ * WC tested up to: 3.5.4
13
  **/
14
 
15
+ // TODO Try to use jQuery validation in the form.
16
+ // TODO in case Google starts to use alphabetic characters in the conversion ID, output the conversion ID with ''
17
+ // TODO give users choice to use content or footer based code insertion
18
+ // TODO only run if WooCommerce is active
19
+ // TODO fix json_encode for order total with only two decimals https://stackoverflow.com/questions/42981409/php7-1-json-encode-float-issue
20
+ // TODO also json_encode might not return the correct format under certain locales http://php.net/manual/en/function.json-encode.php#91434
21
+
22
+
23
+
24
  if ( ! defined( 'ABSPATH' ) ) {
25
  exit; // Exit if accessed directly
26
  }
28
 
29
  class WGACT {
30
 
31
+ public $conversion_id;
32
+ public $conversion_label;
33
+
34
  public function __construct() {
35
 
36
+
37
+ // preparing the DB check and upgrade routine
38
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-db-upgrade.php';
39
+
40
+ // running the DB updater
41
+ $db_upgrade = new WGACT_DB_Upgrade();
42
+ $db_upgrade->run_options_db_upgrade();
43
+
44
  // startup all functions
45
  $this->init();
46
 
49
  // startup all functions
50
  public function init() {
51
 
52
+ // load the options
53
+ $this->wgact_options_init();
54
+
55
  // add the admin options page
56
  add_action( 'admin_menu', array( $this, 'wgact_plugin_admin_add_page' ), 99 );
57
 
64
  // Load textdomain
65
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
66
 
67
+ // ask for a rating in a plugin notice
68
+ add_action( 'admin_head', array( $this, 'ask_for_rating_js' ) );
69
+ add_action( 'wp_ajax_wgact_dismissed_notice_handler', array( $this, 'ajax_rating_notice_handler' ) );
70
+ add_action( 'admin_notices', array( $this, 'ask_for_rating_notices_if_not_asked_before' ) );
71
+
72
+ // add the Google Ads tag to the thankyou part of the page within the body tags
73
+ add_action( 'wp_head', array( $this, 'GoogleAdWordsTag' ) );
74
+
75
+ // fix WordPress CDATA filter as per ticket https://core.trac.wordpress.org/ticket/3670
76
+ add_action( 'template_redirect', array( $this, 'cdata_template_redirect' ), -1 );
77
+
78
+ }
79
+
80
+ // start cdata template markupfix
81
+ function cdata_template_redirect( $content ) {
82
+ ob_start( array( $this, 'cdata_markupfix' ) );
83
+ }
84
+
85
+ // execute str_replace on content to fix the CDATA comments
86
+ function cdata_markupfix( $content ) {
87
+ $content = str_replace("]]&gt;", "]]>", $content);
88
+
89
+ return $content;
90
+ }
91
+
92
+ // client side ajax js handler for the admin rating notice
93
+ public function ask_for_rating_js() {
94
+
95
+ ?>
96
+ <script type="text/javascript">
97
+ jQuery(document).on('click', '.notice-success.wgact-rating-success-notice, wgact-rating-link, .wgact-rating-support', function ($) {
98
+
99
+ var data = {
100
+ 'action': 'wgact_dismissed_notice_handler',
101
+ };
102
+
103
+ jQuery.post(ajaxurl, data);
104
+ jQuery('.wgact-rating-success-notice').remove();
105
+
106
+ });
107
+ </script> <?php
108
+
109
+ }
110
+
111
+ // server side php ajax handler for the admin rating notice
112
+ public function ajax_rating_notice_handler() {
113
+
114
+ // prepare the data that needs to be written into the user meta
115
+ $wgdr_admin_notice_user_meta = array(
116
+ 'date-dismissed' => date( 'Y-m-d' ),
117
+ );
118
+
119
+ // update the user meta
120
+ update_user_meta( get_current_user_id(), 'wgact_admin_notice_user_meta', $wgdr_admin_notice_user_meta );
121
+
122
+ wp_die(); // this is required to terminate immediately and return a proper response
123
+ }
124
+
125
+
126
+ // only ask for rating if not asked before or longer than a year
127
+ public function ask_for_rating_notices_if_not_asked_before() {
128
+
129
+ // get user meta data for this plugin
130
+ $user_meta = get_user_meta( get_current_user_id(), 'wgact_admin_notice_user_meta' );
131
+
132
+ // check if there is already a saved value in the user meta
133
+ if ( isset( $user_meta[0]['date-dismissed'] ) ) {
134
+
135
+ $date_1 = date_create( $user_meta[0]['date-dismissed'] );
136
+ $date_2 = date_create( date( 'Y-m-d' ) );
137
+
138
+ // calculate day difference between the dates
139
+ $interval = date_diff( $date_1, $date_2 );
140
+
141
+ // check if the date difference is more than 360 days
142
+ if ( 360 < $interval->format( '%a' ) ) {
143
+ $this->ask_for_rating_notices();
144
+ }
145
+
146
+ } else {
147
+
148
+ $this->ask_for_rating_notices();
149
+ }
150
+ }
151
+
152
+ // show an admin notice to ask for a plugin rating
153
+ public function ask_for_rating_notices() {
154
+
155
+ $current_user = wp_get_current_user();
156
+
157
+ ?>
158
+ <div class="notice notice-success is-dismissible wgact-rating-success-notice">
159
+ <p>
160
+ <span><?php _e( 'Hi ', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></span>
161
+ <span><?php echo( $current_user->user_firstname ? $current_user->user_firstname : $current_user->nickname ); ?></span>
162
+ <span><?php _e( '! ', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></span>
163
+ <span><?php _e( 'You\'ve been using the ', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></span>
164
+ <span><b><?php _e( 'WGACT Google Ads Conversion Tracking Plugin', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></b></span>
165
+ <span><?php _e( ' for a while now. If you like the plugin please support our development by leaving a ★★★★★ rating: ', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></span>
166
+ <span class="wgact-rating-link">
167
+ <a href="https://wordpress.org/support/view/plugin-reviews/woocommerce-google-adwords-conversion-tracking-tag?rate=5#postform"
168
+ target="_blank"><?php _e( 'Rate it!', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></a>
169
+ </span>
170
+ </p>
171
+ <p>
172
+ <span><?php _e( 'Or else, please leave us a support question in the forum. We\'ll be happy to assist you: ', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></span>
173
+ <span class="wgact-rating-support">
174
+ <a href="https://wordpress.org/support/plugin/woocommerce-google-adwords-conversion-tracking-tag"
175
+ target="_blank"><?php _e( 'Get support', 'woocommerce-google-adwords-conversion-tracking-tag' ); ?></a>
176
+ </span>
177
+ </p>
178
+ </div>
179
+ <?php
180
+
181
+ }
182
+
183
 
184
+ // initialise the options
185
+ public function wgact_options_init() {
186
+
187
+ // set options equal to defaults
188
+ global $wgact_plugin_options;
189
+ $wgact_plugin_options = get_option( 'wgact_plugin_options' );
190
+
191
+ if ( false === $wgact_plugin_options ) {
192
+
193
+ $wgact_plugin_options = $this->wgact_get_default_options();
194
+ update_option( 'wgact_plugin_options', $wgact_plugin_options );
195
+
196
+ } else { // Check if each single option has been set. If not, set them. That is necessary when new options are introduced.
197
+
198
+ // get default plugins options
199
+ $wgact_default_plugin_options = $this->wgact_get_default_options();
200
+
201
+ // go through all default options an find out if the key has been set in the current options already
202
+ foreach ( $wgact_default_plugin_options as $key => $value ) {
203
+
204
+ // Test if the key has been set in the options already
205
+ if ( ! array_key_exists( $key, $wgact_plugin_options ) ) {
206
+
207
+ // set the default key and value in the options table
208
+ $wgact_plugin_options[ $key ] = $value;
209
+
210
+ // update the options table with the new key
211
+ update_option( 'wgact_plugin_options', $wgact_plugin_options );
212
+
213
+ }
214
+ }
215
+ }
216
  }
217
 
218
+ // get the default options
219
+ public function wgact_get_default_options() {
220
+ // default options settings
221
+ $options = array(
222
+ 'conversion_id' => '',
223
+ 'conversion_label' => '',
224
+ 'order_total_logic' => 0,
225
+ );
226
+
227
+ return $options;
228
+ }
229
+
230
+
231
  // Load text domain function
232
  public function load_plugin_textdomain() {
233
  load_plugin_textdomain( 'woocommerce-google-adwords-conversion-tracking-tag', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
245
  // add the admin options page
246
  function wgact_plugin_admin_add_page() {
247
  //add_options_page('WGACT Plugin Page', 'WGACT Plugin Menu', 'manage_options', 'wgact', array($this, 'wgact_plugin_options_page'));
248
+ add_submenu_page( 'woocommerce', esc_html__( 'Google Ads Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), esc_html__( 'Google Ads Conversion Tracking', 'woocommerce-google-adwords-conversion-tracking-tag' ), 'manage_options', 'wgact', array(
249
  $this,
250
+ 'wgact_plugin_options_page',
251
  ) );
252
  }
253
 
256
 
257
  ?>
258
 
259
+ <br>
260
+ <div style="width:980px; float: left; margin: 5px">
261
+ <div style="float:left; margin: 5px; margin-right:20px; width:750px">
262
+ <div style="background: #0073aa; padding: 10px; font-weight: bold; color: white; border-radius: 2px">
263
+ <?php esc_html_e( 'Google Ads Conversion Tracking Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
264
+ </div>
265
+ <form action="options.php" method="post">
266
+ <?php settings_fields( 'wgact_plugin_options_settings_fields' ); ?>
 
 
 
 
267
  <?php do_settings_sections( 'wgact' ); ?>
268
+ <br>
269
+ <table class="form-table" style="margin: 10px">
270
+ <tr>
271
+ <th scope="row" style="white-space: nowrap">
272
+ <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>"
273
+ class="button button-primary"/>
274
+ </th>
275
+ </tr>
276
+ </table>
277
+ </form>
278
+
279
+ <br>
280
+ <div
281
+ style="background: #0073aa; padding: 10px; font-weight: bold; color: white; margin-bottom: 20px; border-radius: 2px">
282
  <span>
283
  <?php esc_html_e( 'Profit Driven Marketing by Wolf+Bär', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
284
  </span>
285
+ <span style="float: right;">
286
+ <a href="https://wolfundbaer.ch/"
287
+ target="_blank" style="color: white">
288
+ <?php esc_html_e( 'Visit us here: https://wolfundbaer.ch', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
289
  </a>
290
  </span>
291
+ </div>
292
+ </div>
293
+ <div style="float: left; margin: 5px">
294
+ <a href="https://wordpress.org/plugins/woocommerce-google-dynamic-retargeting-tag/" target="_blank">
295
+ <img src="<?php echo( plugins_url( 'images/wgdr-icon-256x256.png', __FILE__ ) ) ?>" width="150px"
296
+ height="150px">
297
+ </a>
298
+ </div>
299
+ <div style="float: left; margin: 5px">
300
+ <a href="https://wordpress.org/plugins/woocommerce-google-adwords-conversion-tracking-tag/"
301
+ target="_blank">
302
+ <img src="<?php echo( plugins_url( 'images/wgact-icon-256x256.png', __FILE__ ) ) ?>" width="150px"
303
+ height="150px">
304
+ </a>
305
+ </div>
306
+ </div>
307
  <?php
308
  }
309
 
310
 
311
  // add the admin settings and such
312
  function wgact_plugin_admin_init() {
313
+
314
+ //register_setting( 'wgact_plugin_options_settings_fields', 'wgact_plugin_options', 'wgact_plugin_options_validate');
315
+ register_setting( 'wgact_plugin_options_settings_fields', 'wgact_plugin_options', array( $this, 'wgact_plugin_options_validate') );
316
+ //error_log('after register setting');
317
+
318
  add_settings_section( 'wgact_plugin_main', esc_html__( 'Settings', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
319
  $this,
320
+ 'wgact_plugin_section_text',
321
  ), 'wgact' );
322
+
323
+ // add the field for the conversion id
324
+ add_settings_field( 'wgact_plugin_conversion_id', esc_html__( 'Conversion ID', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
325
  $this,
326
+ 'wgact_plugin_setting_conversion_id',
327
  ), 'wgact', 'wgact_plugin_main' );
328
+
329
+ // ad the field for the conversion label
330
+ add_settings_field( 'wgact_plugin_conversion_label', esc_html__( 'Conversion Label', 'woocommerce-google-adwords-conversion-tracking-tag' ), array(
331
  $this,
332
+ 'wgact_plugin_setting_conversion_label',
333
  ), 'wgact', 'wgact_plugin_main' );
 
334
 
335
+ // add fields for the product identifier
336
+ add_settings_field(
337
+ 'wgact_plugin_order_total_logic',
338
+ esc_html__(
339
+ 'Order Total Logic',
340
+ 'woocommerce-google-adwords-conversion-tracking-tag'
341
+ ),
342
+ array(
343
+ $this,
344
+ 'wgact_plugin_setting_order_total_logic',
345
+ ),
346
+ 'wgact',
347
+ 'wgact_plugin_main'
348
+ );
349
  }
350
 
351
+ function wgact_plugin_section_text() {
352
+ //echo '<p>Woocommerce Google Ads Conversion Tracking Tag</p>';
 
 
353
  }
 
354
 
355
+ function wgact_plugin_setting_conversion_id() {
356
+ $options = get_option( 'wgact_plugin_options' );
357
+ echo "<input id='wgact_plugin_conversion_id' name='wgact_plugin_options[conversion_id]' size='40' type='text' value='{$options['conversion_id']}' />";
358
  }
359
 
360
+ function wgact_plugin_setting_conversion_label() {
361
+ $options = get_option( 'wgact_plugin_options' );
362
+ echo "<input id='wgact_plugin_conversion_label' name='wgact_plugin_options[conversion_label]' size='40' type='text' value='{$options['conversion_label']}' />";
363
  }
364
 
365
+ function wgact_plugin_setting_order_total_logic() {
366
+ $options = get_option( 'wgact_plugin_options' );
367
+ ?>
368
+ <input type='radio' id='wgact_plugin_option_product_identifier_0' name='wgact_plugin_options[order_total_logic]'
369
+ value='0' <?php echo( checked( 0, $options['order_total_logic'], false ) ) ?> ><?php _e( 'Use order_subtotal: Doesn\'t include tax and shipping (default)', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
370
+ <br>
371
+ <input type='radio' id='wgact_plugin_option_product_identifier_1' name='wgact_plugin_options[order_total_logic]'
372
+ value='1' <?php echo( checked( 1, $options['order_total_logic'], false ) ) ?> ><?php _e( 'Use order_total: Includes tax and shipping', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
373
+ <br><br>
374
+ <?php _e( 'This is the order total amount reported back to Google Ads', 'woocommerce-google-adwords-conversion-tracking-tag' ) ?>
375
+ <?php
376
  }
 
377
 
378
  // validate our options
379
  function wgact_plugin_options_validate( $input ) {
 
 
 
 
380
 
381
+ // Create our array for storing the validated options
382
+ $output = array();
383
+
384
+ // validate and sanitize conversion_id
385
+
386
+ $needles_cid = array( 'AW-', '"',);
387
+ $replacements_cid = array( '', '');
388
+
389
+ // clean
390
+ $output['conversion_id'] = wp_strip_all_tags( str_ireplace( $needles_cid, $replacements_cid, $input['conversion_id'] ) );
391
+
392
+ // validate and sanitize conversion_label
393
+
394
+ $needles_cl = array( '"' );
395
+ $replacements_cl = array( '' );
396
+
397
+ $output['conversion_label'] = wp_strip_all_tags( str_ireplace( $needles_cl, $replacements_cl, $input['conversion_label'] ) );
398
+
399
+ $output['order_total_logic'] = $input['order_total_logic'];
400
+
401
+ // Return the array processing any additional functions filtered by this action
402
+ // return apply_filters( 'sandbox_theme_validate_input_examples', $output, $input );
403
+ return $output;
404
  }
405
 
406
+ function woocommerce_3_and_above(){
407
+ global $woocommerce;
408
+ if( version_compare( $woocommerce->version, 3.0, ">=" ) ) {
409
+ return true;
410
+ } else {
411
+ return false;
412
+ }
413
+ }
414
+
415
+ public function GoogleAdWordsTag() {
416
 
417
  $conversion_id = $this->get_conversion_id();
418
  $conversion_label = $this->get_conversion_label();
419
 
 
 
 
 
 
420
 
421
+ ?>
422
+ <!--noptimize-->
423
+ <!-- Global site tag (gtag.js) - Google Ads: <?php echo esc_html( $conversion_id ) ?> -->
424
+ <script async src="https://www.googletagmanager.com/gtag/js?id=AW-<?php echo esc_html( $conversion_id ) ?>"></script>
425
+ <script>
426
+ window.dataLayer = window.dataLayer || [];
427
+ function gtag(){dataLayer.push(arguments);}
428
+ gtag('js', new Date());
429
 
430
+ gtag('config', 'AW-<?php echo esc_html( $conversion_id ) ?>');
431
+ </script>
432
+ <!--/noptimize-->
433
 
 
434
  <?php
435
 
 
 
 
 
 
436
 
437
+ if ( is_order_received_page() ) {
 
 
 
438
 
439
 
 
 
 
 
440
 
441
+ // get order from URL and evaluate order total
442
+ $order_key = $_GET['key'];
443
+ $order = new WC_Order( wc_get_order_id_by_order_key( $order_key ) );
444
 
445
+ $options = get_option( 'wgact_plugin_options' );
446
+ $order_total_setting = $options['order_total_logic'];
447
+ $order_total = 0 == $order_total_setting ? $order->get_subtotal() : $order->get_total();
448
+ $order_total = $order_total - $order->get_total_discount();
449
 
450
+ // use the right function to get the currency depending on the WooCommerce version
451
+ $order_currency = $this->woocommerce_3_and_above() ? $order->get_currency() : $order->get_order_currency();
452
 
 
453
 
454
+ // the filter is deprecated
455
+ // $order_total_filtered = apply_filters( 'wgact_conversion_value_filter', $order_total, $order );
456
+
457
+
458
+ ?>
459
+
460
+ <!--noptimize-->
461
+ <!-- Global site tag (gtag.js) - Google Ads: <?php echo esc_html( $conversion_id ) ?> -->
462
+ <?php
463
+
464
+ // Only run conversion script if the payment has not failed. (has_status('completed') is too restrictive)
465
+ // Also don't run the pixel if an admin or shop manager is logged in.
466
+ // TODO $order->get_order_currency() is deprecated. Switch to $order->get_currency() at a later point somewhen in 2018
467
+ if ( ! $order->has_status( 'failed' ) && ! current_user_can( 'edit_others_pages' ) ) {
468
+ ?>
469
+
470
+ <!-- Event tag for WooCommerce Checkout conversion page -->
471
+ <script>
472
+ gtag('event', 'conversion', {
473
+ 'send_to': 'AW-<?php echo esc_html( $conversion_id ) ?>/<?php echo esc_html( $conversion_label ) ?>',
474
+ 'value': <?php echo $order_total; ?>,
475
+ 'currency': <?php echo json_encode( $order_currency ); ?>,
476
+ 'transaction_id': '<?php echo $order->get_order_number(); ?>',
477
+ });
478
+ </script>
479
+ <?php
480
+
481
+ } else {
482
+
483
+ ?>
484
+
485
+ <!-- The Google Ads pixel has not been inserted. Possible reasons: -->
486
+ <!-- You are logged into WooCommerce as admin or shop manager. -->
487
+ <!-- The order payment has failed. -->
488
+ <!-- The pixel has already been fired. To prevent double counting the pixel is not being fired again. -->
489
+
490
+ <?php
491
+ } // end if order status
492
+
493
+ ?>
494
+
495
+ <!-- END Google Code for Sales (Google Ads) Conversion Page -->
496
+ <!--/noptimize-->
497
+ <?php
498
+ }
499
  }
500
 
501
  private function get_conversion_id() {
502
+ $opt = get_option( 'wgact_plugin_options' );
503
+ $conversion_id = $opt['conversion_id'];
504
 
505
  return $conversion_id;
506
  }
507
 
508
+ // insert the Google Ads tag into the page
509
 
510
  private function get_conversion_label() {
511
+ $opt = get_option( 'wgact_plugin_options' );
512
+ $conversion_label = $opt['conversion_label'];
513
 
514
  return $conversion_label;
515
  }