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

Version Description

Download this release

Release Info

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

Version 0.1.1

Files changed (2) hide show
  1. readme.txt +34 -0
  2. wgact.php +222 -0
readme.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: alekv
3
+ Donate link: http://www.wolfundbaer.ch/donations/
4
+ Tags: WooCommerce, Google AdWords, conversion tag, conversion value tracking
5
+ Requires at least: 3.0.1
6
+ Tested up to: 3.6
7
+ Stable tag: 0.1.1
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ This plugin inserts a Google AdWords conversion tracking tag into the thankyou page of a WooCommerce shop, also measuring the conversion value.
12
+
13
+ == Description ==
14
+
15
+ This plugin fills a small gap in the tracking of Google AdWords conversions in conjunction with WooCommerce. Whereas other available plugins inject a static AdWords tracking tag, this plugin is dynamic and enables the tracking code to also measure the total value of the transaction. This is important if you want to measure the ROI of the AdWords account. Sure this can be done in different ways, but for everyone who would like to use this feature with WooCommerce and AdWords, this is the right plugin. It has been tested with Wordpress 3.6, WooCommerce 2.0.13 and the WooCommerce theme Wootique 1.6.7, though the plugin should work with all WooCommerce themes.
16
+
17
+ == Installation ==
18
+
19
+ 1. Upload the wgact plugin directory into your `/wp-content/plugins/` directory
20
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
21
+ 3. In the WordpPress admin panel go to settings and the into the WGACT Plugin Menu. Please enter the necessary settings for your installation.
22
+
23
+ == Frequently Asked Questions ==
24
+
25
+ = Where can I report a bug or suggest improvements? =
26
+
27
+ Please follow this link to report bugs or suggest improvements: http://www.wolfundbaer.ch/woocommerce-google-adwords-conversion-tracking-tag/?lang=en
28
+
29
+ == Screenshots ==
30
+
31
+ == Changelog ==
32
+
33
+ = 0.1 =
34
+ * This is the initial release of the plugin. There are no known bugs so far.
wgact.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*********************************************************************************************************************************************************************************************************************************
4
+
5
+ Plugin Name: WooCommerce Google AdWords conversion tracking tag
6
+ Plugin URI: http://www.wolfundbaer.ch
7
+ Description: This plugin fills a small gap in the tracking of Google AdWords conversions in conjunction with WooCommerce. Whereas other available plugins inject a static AdWords tracking tag, this plugin is dynamic and enables the tracking code to also measure the total value of the transaction. This is important if you want to measure the ROI of the AdWords account. Sure this can be done in different ways, but for everyone who would like to use this feature with WooCommerce and AdWords, this is the right plugin. It has been tested with Wordpress 3.6, WooCommerce 2.0.13 and the WooCommerce theme Wootique 1.6.7, though the plugin should work with all WooCommerce themes.
8
+ Version: 0.1.1
9
+ Author: Wolf & Bär
10
+ Author URI: http://www.wolfundbaer.ch
11
+
12
+ ********************************************************************************************************************************************************************************************************************************/
13
+
14
+
15
+ class WGACT{
16
+
17
+ public function __construct(){
18
+
19
+ // check if WooCommerce is installed.
20
+ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
21
+
22
+ // insert the tracking code into the footer of the WooCommerce page
23
+ add_action( 'woo_foot', array( $this, 'GoogleAdWordsTag' ));
24
+ }
25
+ //add_action( 'wp_head', array( $this, 'testecho' ));
26
+
27
+ // add the admin options page
28
+ add_action('admin_menu', array( $this, 'wgact_plugin_admin_add_page'));
29
+
30
+ // install a settings page in the admin console
31
+ add_action('admin_init', array( $this, 'wgact_plugin_admin_init'));
32
+
33
+
34
+ }
35
+
36
+
37
+ // add the admin options page
38
+ function wgact_plugin_admin_add_page() {
39
+ add_options_page('WGACT Plugin Page', 'WGACT Plugin Menu', 'manage_options', 'do_wgact', array($this, 'wgact_plugin_options_page'));
40
+ }
41
+
42
+
43
+
44
+ // display the admin options page
45
+ function wgact_plugin_options_page() {
46
+
47
+ // Throw a warning if WooCommerce is disabled.
48
+ if (! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
49
+
50
+ echo '<div><h1><font color="red"><b>WooCommerce not active -> tag insertion disabled !</b></font></h1></div>';
51
+ }
52
+
53
+ ?>
54
+ <div>
55
+ <h2>WooCommerce Google AdWords conversion tracking tag</h2>
56
+
57
+
58
+ <form action="options.php" method="post">
59
+ <?php settings_fields('wgact_plugin_options'); ?>
60
+ <?php do_settings_sections('do_wgact'); ?>
61
+
62
+ <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
63
+ </form></div>
64
+
65
+ <p>.<p>.<p>
66
+ <div><h3>This plugin was developed by <a href="http://www.wolfundbaer.ch" target="_blank">Wolf & Bär</a><p>Buy me a beer if you like the plugin.<br>
67
+ If you want me to continue developing the plugin buy me a few more beers.</h3></div>
68
+
69
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
70
+ <input type="hidden" name="cmd" value="_s-xclick">
71
+ <input type="hidden" name="hosted_button_id" value="UE3D2AW8YTML8">
72
+ <input type="image" src="https://www.paypalobjects.com/en_US/CH/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
73
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
74
+ </form>
75
+
76
+
77
+ <?php
78
+
79
+
80
+ }
81
+
82
+
83
+ // add the admin settings and such
84
+
85
+ function wgact_plugin_admin_init(){
86
+ //register_setting( 'plugin_options', 'plugin_options', 'wgact_plugin_options_validate' );
87
+ register_setting( 'wgact_plugin_options', 'wgact_plugin_options_1');
88
+ register_setting( 'wgact_plugin_options', 'wgact_plugin_options_2');
89
+ // register_setting( 'wgact_plugin_options', 'wgact_plugin_options_3');
90
+ add_settings_section('wgact_plugin_main', 'WGACT Main Settings', array($this,'wgact_plugin_section_text'), 'do_wgact');
91
+ add_settings_field('wgact_plugin_text_string_1', 'Conversion ID', array($this,'wgact_plugin_setting_string_1'), 'do_wgact', 'wgact_plugin_main');
92
+ add_settings_field('wgact_plugin_text_string_2', 'Conversion label', array($this,'wgact_plugin_setting_string_2'), 'do_wgact', 'wgact_plugin_main');
93
+ // add_settings_field('wgact_plugin_text_string_3', 'Google Merchant Center prefix', 'wgact_plugin_setting_string_3', 'do_wgact', 'wgact_plugin_main');
94
+ }
95
+
96
+ function wgact_plugin_section_text() {
97
+ echo '<p>Woocommerce Google AdWords conversion tracking tag</p>';
98
+ }
99
+
100
+ /*
101
+ function wgact_plugin_setting_string_1() {
102
+ $options = get_option('wgact_plugin_options_1');
103
+ echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
104
+ }
105
+ */
106
+
107
+ function wgact_plugin_setting_string_1() {
108
+ $options = get_option('wgact_plugin_options_1');
109
+ echo "<input id='wgact_plugin_text_string_1' name='wgact_plugin_options_1[text_string]' size='40' type='text' value='{$options['text_string']}' />";
110
+ }
111
+
112
+ function wgact_plugin_setting_string_2() {
113
+ $options = get_option('wgact_plugin_options_2');
114
+ echo "<input id='wgact_plugin_text_string_2' name='wgact_plugin_options_2[text_string]' size='40' type='text' value='{$options['text_string']}' />";
115
+ }
116
+
117
+ /*
118
+ function wgact_plugin_setting_string_3() {
119
+ $options = get_option('wgact_plugin_options_3');
120
+ echo "<input id='wgact_plugin_text_string_3' name='wgact_plugin_options_3[text_string]' size='40' type='text' value='{$options['text_string']}' />";
121
+ }
122
+ */
123
+
124
+ // validate our options
125
+ function wgact_plugin_options_validate($input) {
126
+ $newinput['text_string'] = trim($input['text_string']);
127
+ if(!preg_match('/^[a-z0-9]{32}$/i', $newinput['text_string'])) {
128
+ $newinput['text_string'] = '';
129
+ }
130
+ return $newinput;
131
+ }
132
+
133
+ // just a test to find out the difference between plubic and private functions
134
+ public function testecho(){
135
+
136
+ echo 'testecho';
137
+ }
138
+
139
+ private function get_conversion_id(){
140
+
141
+ $opt = get_option('wgact_plugin_options_1');
142
+ $conversion_id = $opt['text_string'];
143
+ return $conversion_id;
144
+ }
145
+
146
+ private function get_conversion_label(){
147
+
148
+ $opt = get_option('wgact_plugin_options_2');
149
+ $conversion_label = $opt['text_string'];
150
+ return $conversion_label;
151
+ }
152
+
153
+ private function get_mc_prefix(){
154
+
155
+ $opt = get_option('wgact_plugin_options_3');
156
+ $mc_prefix = $opt['text_string'];
157
+ return $mc_prefix;
158
+ }
159
+
160
+
161
+ public function GoogleAdWordsTag() {
162
+
163
+ global $woocommerce;
164
+
165
+ if(is_order_received_page()){
166
+
167
+ //$conversion_id = '9876543210';
168
+ $conversion_id = $this->get_conversion_id();
169
+ //$conversion_label = 'yYyYyYyY';
170
+ $conversion_label = $this->get_conversion_label();
171
+ //$mc_prefix = 'woocommerce_gpf_';
172
+ $mc_prefix = $this->get_mc_prefix();
173
+
174
+
175
+ // Ugly work around to get most recent order ID. This must be replaced.
176
+ global $wpdb;
177
+
178
+ $recent_order_id = $wpdb->get_var(
179
+ "
180
+ SELECT MAX(id)
181
+ FROM $wpdb->posts
182
+ "
183
+ );
184
+
185
+
186
+ $order = new WC_order($recent_order_id);
187
+ $order_total = $order->get_total();
188
+
189
+ ?>
190
+
191
+ <!-- Google Code for Sales (AdWords) Conversion Page -->
192
+ <!-- inserted by the WGACT WooCommerce plugin developed by http://www.wolfundbaer.ch -->
193
+
194
+ <script type="text/javascript">
195
+ /* <![CDATA[ */
196
+ var google_conversion_id = <?php echo $conversion_id; ?>;
197
+ var google_conversion_language = "de";
198
+ var google_conversion_format = "2";
199
+ var google_conversion_color = "ffffff";
200
+ var google_conversion_label = "<?php echo $conversion_label; ?>";
201
+ var google_conversion_value = <?php echo $order_total; ?>;
202
+ /* ]]> */
203
+ </script>
204
+ <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
205
+ </script>
206
+ <noscript>
207
+ <div style="display:inline;">
208
+ <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/<?php echo $conversion_id; ?>/?value=<?php echo $order_total; ?>&amp;label=<?php echo $conversion_label; ?>&amp;guid=ON&amp;script=0"/>
209
+ </div>
210
+ </noscript>
211
+
212
+
213
+ <?php
214
+
215
+ }
216
+ }
217
+
218
+ }
219
+
220
+ $wgact = new WGACT();
221
+
222
+ ?>