DuracellTomi's Google Tag Manager for WordPress - Version 0.5

Version Description

  • Added: scroll tracking
  • Fixed: social tracking option on the admin panel was being shown as an edit box instead of a checbox
  • Fixed: WooCommerce transaction data was not included in the dataLayer if you selected "Custom" code placement
  • Fixed: do not do anything if you enabled WooCommerce integration but did not activate WooCommerce plugin itself
  • Updated: do not re-declare dataLayer variable if it already exists (because another script already created it before my plugin was run)
Download this release

Release Info

Developer duracelltomi
Plugin Icon 128x128 DuracellTomi's Google Tag Manager for WordPress
Version 0.5
Comparing to
See all releases

Code changes from version 0.4 to 0.5

admin/admin.php CHANGED
@@ -10,6 +10,7 @@ define( 'GTM4WP_ADMIN_GROUP_INFO', 'gtm4wp-admin-group-datalayer-info' );
10
 
11
  define( 'GTM4WP_ADMIN_GROUP_INCLUDES', 'gtm4wp-admin-group-includes' );
12
  define( 'GTM4WP_ADMIN_GROUP_EVENTS', 'gtm4wp-admin-group-events' );
 
13
  define( 'GTM4WP_ADMIN_GROUP_INTEGRATION', 'gtm4wp-admin-group-integration' );
14
  define( 'GTM4WP_ADMIN_GROUP_ADVANCED', 'gtm4wp-admin-group-advanced' );
15
  define( 'GTM4WP_ADMIN_GROUP_CREDITS', 'gtm4wp-admin-group-credits' );
@@ -84,6 +85,33 @@ $GLOBALS["gtm4wp_eventfieldtexts"] = array(
84
  )
85
  );
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  $GLOBALS["gtm4wp_integratefieldtexts"] = array(
88
  GTM4WP_OPTION_INTEGRATE_WPCF7 => array(
89
  "label" => __( "Contact Form 7", GTM4WP_TEXTDOMAIN ),
@@ -122,6 +150,14 @@ function gtm4wp_admin_output_section( $args ) {
122
  break;
123
  }
124
 
 
 
 
 
 
 
 
 
125
  case GTM4WP_ADMIN_GROUP_INTEGRATION: {
126
  _e( "Google Tag Manager for WordPress can integrate with several popular plugins. Please check the plugins you would like to integrate with:", GTM4WP_TEXTDOMAIN );
127
 
@@ -178,7 +214,12 @@ function gtm4wp_admin_output_field( $args ) {
178
  default: {
179
  $optval = $gtm4wp_options[$args["optionfieldid"]];
180
 
181
- switch(gettype($optval)) {
 
 
 
 
 
182
  case "boolean": {
183
  echo '<input type="checkbox" id="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" name="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" value="1" ' . checked( 1, $optval, false ) . ' /><br />' . $args["description"];
184
 
@@ -193,6 +234,20 @@ function gtm4wp_admin_output_field( $args ) {
193
  break;
194
  }
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  default : {
197
  echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" name="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" value="' . esc_attr( $optval ) . '" size="80" /><br />' . $args["description"];
198
  }
@@ -211,18 +266,23 @@ function gtm4wp_sanitize_options($options) {
211
  $newoptionvalue = "";
212
  }
213
 
 
214
  if ( substr($optionname, 0, 8) == "include-" ) {
215
  $output[$optionname] = (boolean) $newoptionvalue;
216
 
 
217
  } else if ( $optionname == GTM4WP_OPTION_EVENTS_DWLEXT ) {
218
  $output[$optionname] = str_replace( " ", "", trim( $newoptionvalue ) );
219
 
 
220
  } else if ( substr($optionname, 0, 6) == "event-" ) {
221
  $output[$optionname] = (boolean) $newoptionvalue;
222
 
 
223
  } else if ( substr($optionname, 0, 10) == "integrate-" ) {
224
  $output[$optionname] = (boolean) $newoptionvalue;
225
 
 
226
  } else if ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) ) {
227
  $newoptionvalue = trim($newoptionvalue);
228
 
@@ -235,13 +295,36 @@ function gtm4wp_sanitize_options($options) {
235
  } else {
236
  $output[$optionname] = $newoptionvalue;
237
  }
238
- } else if ( $optionname == GTM4WP_ADMIN_GROUP_PLACEMENT ) {
 
 
239
  $output[$optionname] = (int) $newoptionvalue;
240
  if ( ( $output[$optionname] < 0) || ( $output[$optionname] > 1 ) ) {
241
  $output[$optionname] = 0;
242
  }
 
 
 
 
 
243
  } else {
244
- $output[$optionname] = $newoptionvalue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  }
246
  }
247
 
@@ -249,7 +332,7 @@ function gtm4wp_sanitize_options($options) {
249
  }
250
 
251
  function gtm4wp_admin_init() {
252
- global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts;
253
 
254
  register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, "gtm4wp_sanitize_options" );
255
 
@@ -328,6 +411,28 @@ function gtm4wp_admin_init() {
328
  );
329
  }
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  add_settings_section(
332
  GTM4WP_ADMIN_GROUP_INTEGRATION,
333
  __( 'Integration', GTM4WP_TEXTDOMAIN ),
10
 
11
  define( 'GTM4WP_ADMIN_GROUP_INCLUDES', 'gtm4wp-admin-group-includes' );
12
  define( 'GTM4WP_ADMIN_GROUP_EVENTS', 'gtm4wp-admin-group-events' );
13
+ define( 'GTM4WP_ADMIN_GROUP_SCROLLER', 'gtm4wp-admin-group-scroller' );
14
  define( 'GTM4WP_ADMIN_GROUP_INTEGRATION', 'gtm4wp-admin-group-integration' );
15
  define( 'GTM4WP_ADMIN_GROUP_ADVANCED', 'gtm4wp-admin-group-advanced' );
16
  define( 'GTM4WP_ADMIN_GROUP_CREDITS', 'gtm4wp-admin-group-credits' );
85
  )
86
  );
87
 
88
+ $GLOBALS["gtm4wp_scrollerfieldtexts"] = array(
89
+ GTM4WP_OPTION_SCROLLER_ENABLED => array(
90
+ "label" => __( "Enabled", GTM4WP_TEXTDOMAIN ),
91
+ "description" => __( "Enable scroll tracker script on your website.", GTM4WP_TEXTDOMAIN )
92
+ ),
93
+ GTM4WP_OPTION_SCROLLER_DEBUGMODE => array(
94
+ "label" => __( "Debug mode", GTM4WP_TEXTDOMAIN ),
95
+ "description" => __( "Fire console.log() commands instead of dataLayer events.", GTM4WP_TEXTDOMAIN )
96
+ ),
97
+ GTM4WP_OPTION_SCROLLER_CALLBACKTIME => array(
98
+ "label" => __( "Time delay before location check", GTM4WP_TEXTDOMAIN ),
99
+ "description" => __( "Enter the number of milliseconds after the script checks the current location. It prevents too many events being fired while scrolling.", GTM4WP_TEXTDOMAIN )
100
+ ),
101
+ GTM4WP_OPTION_SCROLLER_DISTANCE => array(
102
+ "label" => __( "Minimum distance", GTM4WP_TEXTDOMAIN ),
103
+ "description" => __( "The minimum amount of pixels that a visitor has to scroll before we treat the move as scrolling.", GTM4WP_TEXTDOMAIN )
104
+ ),
105
+ GTM4WP_OPTION_SCROLLER_CONTENTID => array(
106
+ "label" => __( "Content ID", GTM4WP_TEXTDOMAIN ),
107
+ "description" => __( "Enter the DOM ID of the content element in your template. Leave it empty for default(content). Do not include the # sign.", GTM4WP_TEXTDOMAIN )
108
+ ),
109
+ GTM4WP_OPTION_SCROLLER_READERTIME => array(
110
+ "label" => __( "Scroller time", GTM4WP_TEXTDOMAIN ),
111
+ "description" => __( "Enter the number of milliseconds after the the scroller user is being treated as a reader, someone who really reads the content, not just scrolls through it.", GTM4WP_TEXTDOMAIN )
112
+ )
113
+ );
114
+
115
  $GLOBALS["gtm4wp_integratefieldtexts"] = array(
116
  GTM4WP_OPTION_INTEGRATE_WPCF7 => array(
117
  "label" => __( "Contact Form 7", GTM4WP_TEXTDOMAIN ),
150
  break;
151
  }
152
 
153
+ case GTM4WP_ADMIN_GROUP_SCROLLER: {
154
+ _e( "Fire tags based on how the visitor scrolls through your page.", GTM4WP_TEXTDOMAIN );
155
+ echo '<br />';
156
+ printf( __( 'Based on the script originaly posted to <a href="%s">Analytics Talk</a>', GTM4WP_TEXTDOMAIN ) , "http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/");
157
+
158
+ break;
159
+ }
160
+
161
  case GTM4WP_ADMIN_GROUP_INTEGRATION: {
162
  _e( "Google Tag Manager for WordPress can integrate with several popular plugins. Please check the plugins you would like to integrate with:", GTM4WP_TEXTDOMAIN );
163
 
214
  default: {
215
  $optval = $gtm4wp_options[$args["optionfieldid"]];
216
 
217
+ // fix wrong data type saved in v0.4
218
+ if ( GTM4WP_OPTION_EVENTS_SOCIAL == $args["optionfieldid"] ) {
219
+ $optval = ( boolean )( $optval );
220
+ }
221
+
222
+ switch( gettype( $optval ) ) {
223
  case "boolean": {
224
  echo '<input type="checkbox" id="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" name="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" value="1" ' . checked( 1, $optval, false ) . ' /><br />' . $args["description"];
225
 
234
  break;
235
  }
236
 
237
+ case "integer": {
238
+ echo '<input type="number" step="1" min="1" class="small-text" id="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" name="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" value="' . esc_attr( $optval ) . '" /><br />' . $args["description"];
239
+
240
+ if ( isset( $args["plugintocheck"] ) ) {
241
+ if ( is_plugin_active( $args["plugintocheck"] ) ) {
242
+ echo "<br />" . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recomment to enable this integration!', GTM4WP_TEXTDOMAIN );
243
+ } else {
244
+ echo "<br />" . __( 'This plugin is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', GTM4WP_TEXTDOMAIN );
245
+ }
246
+ }
247
+
248
+ break;
249
+ }
250
+
251
  default : {
252
  echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" name="' . GTM4WP_OPTIONS . '[' . $args["optionfieldid"] . ']" value="' . esc_attr( $optval ) . '" size="80" /><br />' . $args["description"];
253
  }
266
  $newoptionvalue = "";
267
  }
268
 
269
+ // "include" settings
270
  if ( substr($optionname, 0, 8) == "include-" ) {
271
  $output[$optionname] = (boolean) $newoptionvalue;
272
 
273
+ // tracked download extensions
274
  } else if ( $optionname == GTM4WP_OPTION_EVENTS_DWLEXT ) {
275
  $output[$optionname] = str_replace( " ", "", trim( $newoptionvalue ) );
276
 
277
+ // dataLayer events
278
  } else if ( substr($optionname, 0, 6) == "event-" ) {
279
  $output[$optionname] = (boolean) $newoptionvalue;
280
 
281
+ // integrations
282
  } else if ( substr($optionname, 0, 10) == "integrate-" ) {
283
  $output[$optionname] = (boolean) $newoptionvalue;
284
 
285
+ // GTM code or dataLayer variable name
286
  } else if ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) ) {
287
  $newoptionvalue = trim($newoptionvalue);
288
 
295
  } else {
296
  $output[$optionname] = $newoptionvalue;
297
  }
298
+
299
+ // GTM container code placement
300
+ } else if ( $optionname == GTM4WP_OPTION_GTM_PLACEMENT ) {
301
  $output[$optionname] = (int) $newoptionvalue;
302
  if ( ( $output[$optionname] < 0) || ( $output[$optionname] > 1 ) ) {
303
  $output[$optionname] = 0;
304
  }
305
+
306
+ // scroll tracking content ID
307
+ } else if ( $optionname == GTM4WP_OPTION_SCROLLER_CONTENTID ) {
308
+ $output[$optionname] = trim( str_replace( "#", "", $newoptionvalue ) );
309
+ // anything else
310
  } else {
311
+ switch( gettype($optionvalue)) {
312
+ case "boolean": {
313
+ $output[$optionname] = (boolean) $newoptionvalue;
314
+
315
+ break;
316
+ }
317
+
318
+ case "integer": {
319
+ $output[$optionname] = (int) $newoptionvalue;
320
+
321
+ break;
322
+ }
323
+
324
+ default: {
325
+ $output[$optionname] = $newoptionvalue;
326
+ }
327
+ } // end switch
328
  }
329
  }
330
 
332
  }
333
 
334
  function gtm4wp_admin_init() {
335
+ global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts;
336
 
337
  register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, "gtm4wp_sanitize_options" );
338
 
411
  );
412
  }
413
 
414
+ add_settings_section(
415
+ GTM4WP_ADMIN_GROUP_SCROLLER,
416
+ __( 'Scroll tracking', GTM4WP_TEXTDOMAIN ),
417
+ 'gtm4wp_admin_output_section',
418
+ GTM4WP_ADMINSLUG
419
+ );
420
+
421
+ foreach($gtm4wp_scrollerfieldtexts as $fieldid => $fielddata) {
422
+ add_settings_field(
423
+ "gtm4wp-admin-" . $fieldid . "-id",
424
+ $fielddata["label"],
425
+ 'gtm4wp_admin_output_field',
426
+ GTM4WP_ADMINSLUG,
427
+ GTM4WP_ADMIN_GROUP_SCROLLER,
428
+ array(
429
+ "label_for" => "gtm4wp-options[" . $fieldid . "]",
430
+ "description" => $fielddata["description"],
431
+ "optionfieldid" => $fieldid
432
+ )
433
+ );
434
+ }
435
+
436
  add_settings_section(
437
  GTM4WP_ADMIN_GROUP_INTEGRATION,
438
  __( 'Integration', GTM4WP_TEXTDOMAIN ),
common/readoptions.php CHANGED
@@ -22,6 +22,13 @@ define( 'GTM4WP_OPTION_EVENTS_EMAILCLICKS', 'event-email-clicks' );
22
  define( 'GTM4WP_OPTION_EVENTS_FORMMOVE', 'event-form-move' );
23
  define( 'GTM4WP_OPTION_EVENTS_SOCIAL', 'event-social' );
24
 
 
 
 
 
 
 
 
25
  define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
26
  define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE', 'integrate-woocommerce' );
27
  define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
@@ -52,7 +59,14 @@ $gtm4wp_defaultoptions = array(
52
  GTM4WP_OPTION_EVENTS_DWLEXT => "pdf,doc,docx,xls,xlsx,ppt,pptx,zip,rar,gz,tar",
53
  GTM4WP_OPTION_EVENTS_EMAILCLICKS => false,
54
  GTM4WP_OPTION_EVENTS_FORMMOVE => true,
55
- GTM4WP_OPTION_EVENTS_FORMMOVE => false,
 
 
 
 
 
 
 
56
 
57
  GTM4WP_OPTION_INTEGRATE_WPCF7 => true,
58
  GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE => false,
22
  define( 'GTM4WP_OPTION_EVENTS_FORMMOVE', 'event-form-move' );
23
  define( 'GTM4WP_OPTION_EVENTS_SOCIAL', 'event-social' );
24
 
25
+ define( 'GTM4WP_OPTION_SCROLLER_ENABLED', 'scroller-enabled' );
26
+ define( 'GTM4WP_OPTION_SCROLLER_DEBUGMODE', 'scroller-debug-mode' );
27
+ define( 'GTM4WP_OPTION_SCROLLER_CALLBACKTIME', 'scroller-callback-time' );
28
+ define( 'GTM4WP_OPTION_SCROLLER_DISTANCE', 'scroller-distance' );
29
+ define( 'GTM4WP_OPTION_SCROLLER_CONTENTID', 'scroller-contentid' );
30
+ define( 'GTM4WP_OPTION_SCROLLER_READERTIME', 'scroller-readertime' );
31
+
32
  define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
33
  define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE', 'integrate-woocommerce' );
34
  define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
59
  GTM4WP_OPTION_EVENTS_DWLEXT => "pdf,doc,docx,xls,xlsx,ppt,pptx,zip,rar,gz,tar",
60
  GTM4WP_OPTION_EVENTS_EMAILCLICKS => false,
61
  GTM4WP_OPTION_EVENTS_FORMMOVE => true,
62
+ GTM4WP_OPTION_EVENTS_SOCIAL => false,
63
+
64
+ GTM4WP_OPTION_SCROLLER_ENABLED => false,
65
+ GTM4WP_OPTION_SCROLLER_DEBUGMODE => false,
66
+ GTM4WP_OPTION_SCROLLER_CALLBACKTIME => 100,
67
+ GTM4WP_OPTION_SCROLLER_DISTANCE => 150,
68
+ GTM4WP_OPTION_SCROLLER_CONTENTID => "content",
69
+ GTM4WP_OPTION_SCROLLER_READERTIME => 60,
70
 
71
  GTM4WP_OPTION_INTEGRATE_WPCF7 => true,
72
  GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE => false,
duracelltomi-google-tag-manager-for-wordpress.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
- Version: 0.4
5
  Plugin URI: http://www.duracelltomi.com/google-tag-manager-for-wordpress/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
8
  Author URI: http://www.duracelltomi.com/
9
  */
10
 
11
- define( 'GTM4WP_VERSION', '0.4' );
12
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
13
  define( 'GTM4WP_TEXTDOMAIN', 'gtm4wp-lang' );
14
 
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
+ Version: 0.5
5
  Plugin URI: http://www.duracelltomi.com/google-tag-manager-for-wordpress/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
8
  Author URI: http://www.duracelltomi.com/
9
  */
10
 
11
+ define( 'GTM4WP_VERSION', '0.5' );
12
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
13
  define( 'GTM4WP_TEXTDOMAIN', 'gtm4wp-lang' );
14
 
integration/woocommerce.php CHANGED
@@ -1,90 +1,6 @@
1
  <?php
2
- $gtm4wp_woocommerce_completed_order_id = 0;
3
- $gtp4wp_woocommerce_remarketing_sku_list = array();
4
- $gtp4wp_woocommerce_remarketing_totalvalue = 0;
5
-
6
- function gtm4wp_woocommerce_datalayer_filter_order( $dataLayer ) {
7
- global $gtm4wp_woocommerce_completed_order_id, $woocommerce;
8
-
9
- $order = new WC_Order( $gtm4wp_woocommerce_completed_order_id );
10
-
11
- $dataLayer["transactionId"] = $order->get_order_number();
12
- $dataLayer["transactionDate"] = date("c");
13
- $dataLayer["transactionType"] = "sale";
14
- $dataLayer["transactionAffiliation"] = get_bloginfo( 'name' );
15
- $dataLayer["transactionTotal"] = $order->get_total();
16
- $dataLayer["transactionShipping"] = $order->get_shipping();
17
- $dataLayer["transactionTax"] = $order->get_total_tax();
18
- $dataLayer["transactionPaymentType"] = $order->payment_method_title;
19
- $dataLayer["transactionCurrency"] = get_woocommerce_currency();
20
- $dataLayer["transactionShippingMethod"] = $order->get_shipping_method();
21
- $dataLayer["transactionPromoCode"] = implode( ", ", $order->get_used_coupons() );
22
-
23
- $_products = array();
24
- $_sumprice = 0;
25
- $_product_ids = array();
26
-
27
- if ( $order->get_items() ) {
28
- foreach ( $order->get_items() as $item ) {
29
- $_product = $order->get_product_from_item( $item );
30
-
31
- if ( isset( $_product->variation_data ) ) {
32
-
33
- $_category = woocommerce_get_formatted_variation( $_product->variation_data, true );
34
-
35
- } else {
36
- $out = array();
37
- $categories = get_the_terms( $_product->id, 'product_cat' );
38
- if ( $categories ) {
39
- foreach ( $categories as $category ) {
40
- $out[] = $category->name;
41
- }
42
- }
43
-
44
- $_category = implode( " / ", $out );
45
- }
46
-
47
- $_prodprice = $order->get_item_total( $item );
48
- $_products[] = array(
49
- "id" => $_product->id,
50
- "name" => $item['name'],
51
- "sku" => $_product->get_sku() ? __( 'SKU:', GTM4WP_TEXTDOMAIN ) . ' ' . $_product->get_sku() : $_product->id,
52
- "category" => $_category,
53
- "price" => $_prodprice,
54
- "currency" => get_woocommerce_currency(),
55
- "quantity" => $item['qty']
56
- );
57
-
58
- $_sumprice += $_prodprice;
59
- $_product_ids[] = "'" . $_product->id . "'";
60
- }
61
- }
62
-
63
- $dataLayer["transactionProducts"] = $_products;
64
- $dataLayer["event"] = "gtm4wp.orderCompleted";
65
-
66
- $dataLayer["ecomm_prodid"] = '[' . implode(", ", $_product_ids) . ']';
67
- $dataLayer["ecomm_pagetype"] = "purchase";
68
- $dataLayer["ecomm_totalvalue"] = $_sumprice;
69
-
70
- return $dataLayer;
71
- }
72
-
73
- function gtm4wp_woocommerce_thankyou( $order_id ) {
74
- global $gtm4wp_woocommerce_completed_order_id;
75
-
76
- if ( 1 == get_post_meta( $order_id, '_ga_tracked', true ) ) {
77
- return;
78
- }
79
-
80
- $gtm4wp_woocommerce_completed_order_id = $order_id;
81
- add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_order" );
82
-
83
- update_post_meta( $order_id, '_ga_tracked', 1 );
84
- }
85
-
86
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
87
- global $woocommerce, $gtp4wp_woocommerce_remarketing_sku_list, $gtp4wp_woocommerce_remarketing_totalvalue;
88
 
89
  if ( is_front_page() ) {
90
  $dataLayer["ecomm_prodid"] = "";
@@ -120,12 +36,90 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
120
  $dataLayer["ecomm_prodid"] = '[' . implode( ", ", $product_ids ) . ']';
121
  $dataLayer["ecomm_pagetype"] = "cart";
122
  $dataLayer["ecomm_totalvalue"] = $woocommerce->cart->cart_contents_total;
123
- } else if ( !is_order_received_page() ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  $dataLayer["ecomm_pagetype"] = "siteview";
125
  }
126
 
127
  return $dataLayer;
128
  }
129
 
130
- add_action( "woocommerce_thankyou", "gtm4wp_woocommerce_thankyou" );
131
- add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_items" );
 
 
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
3
+ global $woocommerce;
4
 
5
  if ( is_front_page() ) {
6
  $dataLayer["ecomm_prodid"] = "";
36
  $dataLayer["ecomm_prodid"] = '[' . implode( ", ", $product_ids ) . ']';
37
  $dataLayer["ecomm_pagetype"] = "cart";
38
  $dataLayer["ecomm_totalvalue"] = $woocommerce->cart->cart_contents_total;
39
+ } else if ( is_order_received_page() ) {
40
+ $order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET['order'] ) ? 0 : absint( $_GET['order'] ) );
41
+ $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : woocommerce_clean( $_GET['key'] ) );
42
+
43
+ if ( $order_id > 0 ) {
44
+ $order = new WC_Order( $order_id );
45
+ if ( $order->order_key != $order_key )
46
+ unset( $order );
47
+ }
48
+
49
+ if ( 1 == get_post_meta( $order_id, '_ga_tracked', true ) ) {
50
+ unset( $order );
51
+ }
52
+
53
+ if ( isset( $order ) ) {
54
+ $dataLayer["transactionId"] = $order->get_order_number();
55
+ $dataLayer["transactionDate"] = date("c");
56
+ $dataLayer["transactionType"] = "sale";
57
+ $dataLayer["transactionAffiliation"] = get_bloginfo( 'name' );
58
+ $dataLayer["transactionTotal"] = $order->get_total();
59
+ $dataLayer["transactionShipping"] = $order->get_shipping();
60
+ $dataLayer["transactionTax"] = $order->get_total_tax();
61
+ $dataLayer["transactionPaymentType"] = $order->payment_method_title;
62
+ $dataLayer["transactionCurrency"] = get_woocommerce_currency();
63
+ $dataLayer["transactionShippingMethod"] = $order->get_shipping_method();
64
+ $dataLayer["transactionPromoCode"] = implode( ", ", $order->get_used_coupons() );
65
+
66
+ $_products = array();
67
+ $_sumprice = 0;
68
+ $_product_ids = array();
69
+
70
+ if ( $order->get_items() ) {
71
+ foreach ( $order->get_items() as $item ) {
72
+ $_product = $order->get_product_from_item( $item );
73
+
74
+ if ( isset( $_product->variation_data ) ) {
75
+
76
+ $_category = woocommerce_get_formatted_variation( $_product->variation_data, true );
77
+
78
+ } else {
79
+ $out = array();
80
+ $categories = get_the_terms( $_product->id, 'product_cat' );
81
+ if ( $categories ) {
82
+ foreach ( $categories as $category ) {
83
+ $out[] = $category->name;
84
+ }
85
+ }
86
+
87
+ $_category = implode( " / ", $out );
88
+ }
89
+
90
+ $_prodprice = $order->get_item_total( $item );
91
+ $_products[] = array(
92
+ "id" => $_product->id,
93
+ "name" => $item['name'],
94
+ "sku" => $_product->get_sku() ? __( 'SKU:', GTM4WP_TEXTDOMAIN ) . ' ' . $_product->get_sku() : $_product->id,
95
+ "category" => $_category,
96
+ "price" => $_prodprice,
97
+ "currency" => get_woocommerce_currency(),
98
+ "quantity" => $item['qty']
99
+ );
100
+
101
+ $_sumprice += $_prodprice;
102
+ $_product_ids[] = "'" . $_product->id . "'";
103
+ }
104
+ }
105
+
106
+ $dataLayer["transactionProducts"] = $_products;
107
+ $dataLayer["event"] = "gtm4wp.orderCompleted";
108
+
109
+ $dataLayer["ecomm_prodid"] = '[' . implode(", ", $_product_ids) . ']';
110
+ $dataLayer["ecomm_pagetype"] = "purchase";
111
+ $dataLayer["ecomm_totalvalue"] = $_sumprice;
112
+
113
+ update_post_meta( $order_id, '_ga_tracked', 1 );
114
+ }
115
+ } else {
116
  $dataLayer["ecomm_pagetype"] = "siteview";
117
  }
118
 
119
  return $dataLayer;
120
  }
121
 
122
+ // do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
123
+ if ( isset ( $woocommerce ) ) {
124
+ add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_items" );
125
+ }
js/analytics-talk-content-tracking.js ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Source: http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
3
+ * Original authors:
4
+ * - Nick Mihailovski
5
+ * - Thomas Baekdal
6
+ * - Avinash Kaushik
7
+ * - Joost de Valk
8
+ * - Eivind Savio
9
+ * - Justin Cutroni
10
+ *
11
+ * Google Tag Manager dataLayer events added by:
12
+ * Thomas Geiger
13
+ * duracelltomi.com
14
+ */
15
+
16
+ if ( "undefined" == typeof console ) {
17
+ window.console = {
18
+ log: function () {}
19
+ };
20
+ }
21
+
22
+ jQuery( function( $ ) {
23
+ // Debug flag
24
+ var debugMode = gtm4wp_scrollerscript_debugmode;
25
+
26
+ // Default time delay before checking location
27
+ var callBackTime = gtm4wp_scrollerscript_callbacktime;
28
+
29
+ // # px before tracking a reader
30
+ var readerLocation = gtm4wp_scrollerscript_readerlocation;
31
+
32
+ // Set some flags for tracking & execution
33
+ var timer = 0;
34
+ var scroller = false;
35
+ var endContent = false;
36
+ var didComplete = false;
37
+
38
+ // Set some time variables to calculate reading time
39
+ var startTime = new Date();
40
+ var beginning = startTime.getTime();
41
+ var totalTime = 0;
42
+
43
+ // Track the aticle load
44
+ if ( !debugMode ) {
45
+ window[ gtm4wp_datalayer_name ].push({
46
+ 'event': 'gtm4wp.reading.articleLoaded'
47
+ });
48
+ } else {
49
+ console.log( 'Article loaded' );
50
+ }
51
+
52
+ // Check the location and track user
53
+ function trackLocation() {
54
+ bottom = $( window ).height() + $( window ).scrollTop();
55
+ height = $( document ).height();
56
+
57
+ // If user starts to scroll send an event
58
+ if ( bottom > readerLocation && !scroller ) {
59
+ currentTime = new Date();
60
+ scrollStart = currentTime.getTime();
61
+ timeToScroll = Math.round( ( scrollStart - beginning ) / 1000 );
62
+
63
+ if ( !debugMode ) {
64
+ window[ gtm4wp_datalayer_name ].push({
65
+ 'event': 'gtm4wp.reading.startReading',
66
+ 'timeToScroll': timeToScroll
67
+ });
68
+ } else {
69
+ console.log( 'Started reading ' + timeToScroll );
70
+ }
71
+ scroller = true;
72
+ }
73
+
74
+ // If user has hit the bottom of the content send an event
75
+ if ( bottom >= $( '#' + gtm4wp_scrollerscript_contentelementid ).scrollTop() + $( '#' + gtm4wp_scrollerscript_contentelementid ).innerHeight() && !endContent ) {
76
+ currentTime = new Date();
77
+ contentScrollEnd = currentTime.getTime();
78
+ timeToContentEnd = Math.round( ( contentScrollEnd - scrollStart ) / 1000 );
79
+
80
+ if ( !debugMode ) {
81
+ window[ gtm4wp_datalayer_name ].push({
82
+ 'event': 'gtm4wp.reading.contentBottom',
83
+ 'timeToScroll': timeToContentEnd
84
+ });
85
+ } else {
86
+ console.log( 'End content section ' + timeToContentEnd );
87
+ }
88
+
89
+ endContent = true;
90
+ }
91
+
92
+ // If user has hit the bottom of page send an event
93
+ if ( bottom >= height && !didComplete ) {
94
+ currentTime = new Date();
95
+ end = currentTime.getTime();
96
+ totalTime = Math.round( ( end - scrollStart ) / 1000 );
97
+
98
+ if ( !debugMode ) {
99
+ if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
100
+ window[ gtm4wp_datalayer_name ].push({
101
+ 'event': 'gtm4wp.reading.readerType',
102
+ 'readerType': 'scanner'
103
+ });
104
+ } else {
105
+ window[ gtm4wp_datalayer_name ].push({
106
+ 'event': 'gtm4wp.reading.readerType',
107
+ 'readerType': 'reader'
108
+ });
109
+ }
110
+
111
+ window[ gtm4wp_datalayer_name ].push({
112
+ 'event': 'gtm4wp.reading.pagebottom',
113
+ 'timeToScroll': totalTime
114
+ });
115
+ } else {
116
+ if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
117
+ console.log( 'The visitor seems to be a "scanner"' );
118
+ } else {
119
+ console.log( 'The visitor seems to be a "reader"' );
120
+ }
121
+
122
+ console.log( 'Bottom of page ' + totalTime );
123
+ }
124
+
125
+ didComplete = true;
126
+ }
127
+ }
128
+
129
+ // Track the scrolling and track location
130
+ $( window ).scroll(function() {
131
+ if ( timer ) {
132
+ clearTimeout( timer );
133
+ }
134
+
135
+ // Use a buffer so we don't call trackLocation too often.
136
+ timer = setTimeout( trackLocation, callBackTime );
137
+ });
138
+ });
languages/en.pot CHANGED
@@ -355,3 +355,55 @@ msgid ""
355
  "Check this option to include a Tag Manager event when a visitor uses a "
356
  "social button to share/like content on a social network."
357
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  "Check this option to include a Tag Manager event when a visitor uses a "
356
  "social button to share/like content on a social network."
357
  msgstr ""
358
+
359
+ msgid "Enabled"
360
+ msgstr ""
361
+
362
+ msgid "Enable scroll tracker script on your website."
363
+ msgstr ""
364
+
365
+ msgid "Debug mode"
366
+ msgstr "Fire console.log() commands instead of dataLayer events."
367
+
368
+ msgid "Time delay before location check"
369
+ msgstr ""
370
+
371
+ msgid ""
372
+ "Enter the number of milliseconds after the script checks the current "
373
+ "location. It prevents too many events being fired while scrolling."
374
+ msgstr ""
375
+
376
+ msgid "Minimum distance"
377
+ msgstr ""
378
+
379
+ msgid ""
380
+ "The minimum amount of pixels that a visitor has to scroll before we treat "
381
+ "the move as scrolling."
382
+ msgstr ""
383
+
384
+ msgid "Content ID"
385
+ msgstr ""
386
+
387
+ msgid ""
388
+ "Enter the DOM ID of the content element in your template. Leave it empty for "
389
+ "default(content). Do not include the # sign."
390
+ msgstr ""
391
+
392
+ msgid "Scroller time"
393
+ msgstr ""
394
+
395
+ msgid ""
396
+ "Enter the number of milliseconds after the the scroller user is being "
397
+ "treated as a reader, someone who really reads the content, not just scrolls "
398
+ "through it."
399
+ msgstr ""
400
+
401
+ msgid "Fire tags based on how the visitor scrolls through your page."
402
+ msgstr ""
403
+
404
+ msgid ""
405
+ "Based on the script originaly posted to <a href=\"%s\">Analytics Talk</a>"
406
+ msgstr ""
407
+
408
+ msgid "Scroll tracking"
409
+ msgstr ""
languages/gtm4wp-lang-hu_HU.mo CHANGED
Binary file
languages/gtm4wp-lang-hu_HU.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Google Tag Manager for WordPress\n"
4
  "POT-Creation-Date: 2013-09-19 11:27+0100\n"
5
- "PO-Revision-Date: 2013-11-17 15:56+0100\n"
6
  "Last-Translator: Thomas Geiger <duracelltomi@gmail.com>\n"
7
  "Language-Team: JabJab Online Marketing\n"
8
  "Language: English\n"
@@ -443,3 +443,67 @@ msgid ""
443
  msgstr ""
444
  "Kapcsolja be ezt a beállítást, ha szeretne Tag Manager eseményt kiváltani, "
445
  "amikor egy látogató egy közösségi gomb segítségével megoszt/lájkol tartalmat."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  msgstr ""
3
  "Project-Id-Version: Google Tag Manager for WordPress\n"
4
  "POT-Creation-Date: 2013-09-19 11:27+0100\n"
5
+ "PO-Revision-Date: 2013-12-25 16:45+0100\n"
6
  "Last-Translator: Thomas Geiger <duracelltomi@gmail.com>\n"
7
  "Language-Team: JabJab Online Marketing\n"
8
  "Language: English\n"
443
  msgstr ""
444
  "Kapcsolja be ezt a beállítást, ha szeretne Tag Manager eseményt kiváltani, "
445
  "amikor egy látogató egy közösségi gomb segítségével megoszt/lájkol tartalmat."
446
+
447
+ msgid "Enabled"
448
+ msgstr "Engedélyezve"
449
+
450
+ msgid "Enable scroll tracker script on your website."
451
+ msgstr "Görgetés követés engedélyezése az oldalon."
452
+
453
+ msgid "Debug mode"
454
+ msgstr "Hibakereső üzemmód"
455
+
456
+ msgid "Fire console.log() commands instead of dataLayer events."
457
+ msgstr "console.log() parancsok dataLayer események helyett."
458
+
459
+ msgid "Time delay before location check"
460
+ msgstr "Kivárt idő a pozíció ellenőrzésére"
461
+
462
+ msgid ""
463
+ "Enter the number of milliseconds after the script checks the current "
464
+ "location. It prevents too many events being fired while scrolling."
465
+ msgstr ""
466
+ "Adja meg, mennyi milliszekundumot várjon a program az aktuális görgetés "
467
+ "helyének ellenőrzéséhez. Segít abban, hogy ne legyen túl sok esemény a "
468
+ "folyamatos görgetés során. "
469
+
470
+ msgid "Minimum distance"
471
+ msgstr "Minimum távolság"
472
+
473
+ msgid ""
474
+ "The minimum amount of pixels that a visitor has to scroll before we treat "
475
+ "the move as scrolling."
476
+ msgstr ""
477
+ "A legkisebb távolság pixelben, amit a felhasználónak görgetnie kell ahhoz, "
478
+ "hogy mozgásnak vegyük a görgetést."
479
+
480
+ msgid "Content ID"
481
+ msgstr "Tartalom azonosító"
482
+
483
+ msgid ""
484
+ "Enter the DOM ID of the content element in your template. Leave it empty for "
485
+ "default(content). Do not include the # sign."
486
+ msgstr ""
487
+ "Adja meg annak a tartalom DOM elemének az azonosítóját. Hagyja üresen az "
488
+ "alapértelmezetthez (content). Ne használja a # jelet."
489
+
490
+ msgid "Scroller time"
491
+ msgstr "Görgető felhasználó"
492
+
493
+ msgid ""
494
+ "Enter the number of milliseconds after the the scroller user is being "
495
+ "treated as a reader, someone who really reads the content, not just scrolls "
496
+ "through it."
497
+ msgstr ""
498
+ "Adja meg, hány milliszekundum után számít a látogató olvasónak, aki tényleg "
499
+ "el is olvassa a tartalmat, nem csak átfutja."
500
+
501
+ msgid "Fire tags based on how the visitor scrolls through your page."
502
+ msgstr "Címkék aktiválása, ahogy a felhasználó görget az oldalon belül."
503
+
504
+ msgid ""
505
+ "Based on the script originaly posted to <a href=\"%s\">Analytics Talk</a>"
506
+ msgstr "Az <a href=\"%s\">Analytics Talk</a> scriptje alapján."
507
+
508
+ msgid "Scroll tracking"
509
+ msgstr "Görgetés figyelés"
public/frontend.php CHANGED
@@ -212,40 +212,44 @@ function gtm4wp_the_gtm_tag() {
212
  function gtm4wp_enqueue_scripts() {
213
  global $gtm4wp_options, $gtp4wp_plugin_url;
214
 
215
- if ( $gtm4wp_options[GTM4WP_OPTION_EVENTS_OUTBOUND] ) {
216
  wp_enqueue_script( "gtm4wp-outbound-click-tracker", $gtp4wp_plugin_url . "js/gtm4wp-outbound-click-tracker.js", array( "jquery" ), "1.0", false );
217
  }
218
 
219
- if ( $gtm4wp_options[GTM4WP_OPTION_EVENTS_DOWNLOADS] ) {
220
  wp_enqueue_script( "gtm4wp-download-tracker", $gtp4wp_plugin_url . "js/gtm4wp-download-tracker.js", array( "jquery" ), "1.0", false );
221
  }
222
 
223
- if ( $gtm4wp_options[GTM4WP_OPTION_EVENTS_EMAILCLICKS] ) {
224
  wp_enqueue_script( "gtm4wp-email-link-tracker", $gtp4wp_plugin_url . "js/gtm4wp-email-link-tracker.js", array( "jquery" ), "1.0", false );
225
  }
226
 
227
- if ( $gtm4wp_options[GTM4WP_OPTION_INTEGRATE_WPCF7] ) {
228
  wp_enqueue_script( "gtm4wp-contact-form-7-tracker", $gtp4wp_plugin_url . "js/gtm4wp-contact-form-7-tracker.js", array( "jquery" ), "1.0", false );
229
  }
230
 
231
- if ( $gtm4wp_options[GTM4WP_OPTION_EVENTS_FORMMOVE] ) {
232
  wp_enqueue_script( "gtm4wp-form-move-tracker", $gtp4wp_plugin_url . "js/gtm4wp-form-move-tracker.js", array( "jquery" ), "1.0", false );
233
  }
234
 
235
- if ( $gtm4wp_options[GTM4WP_OPTION_EVENTS_SOCIAL] ) {
236
  wp_enqueue_script( "gtm4wp-social-actions", $gtp4wp_plugin_url . "js/gtm4wp-social-tracker.js", array( "jquery" ), "1.0", false );
237
  }
238
 
239
- if ( $gtm4wp_options[GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE] ) {
240
  require_once( dirname( __FILE__ ) . "/../integration/woocommerce.php" );
241
  wp_enqueue_script( "gtm4wp-woocommerce-tracker", $gtp4wp_plugin_url . "js/gtm4wp-woocommerce-tracker.js", array( "jquery" ), "1.0", false );
242
  }
 
 
 
 
243
  }
244
 
245
  function gtm4wp_wp_footer() {
246
  global $gtm4wp_options;
247
 
248
- if ( $gtm4wp_options[GTM4WP_OPTION_GTM_PLACEMENT] == GTM4WP_PLACEMENT_FOOTER ) {
249
  gtm4wp_the_gtm_tag();
250
  }
251
  }
@@ -253,21 +257,35 @@ function gtm4wp_wp_footer() {
253
  function gtm4wp_wp_body_open() {
254
  global $gtm4wp_options;
255
 
256
- if ( $gtm4wp_options[GTM4WP_OPTION_GTM_PLACEMENT] == GTM4WP_PLACEMENT_CUSTOM ) {
257
  gtm4wp_the_gtm_tag();
258
  }
259
  }
260
 
261
  function gtm4wp_wp_header() {
262
- global $gtm4wp_datalayer_name;
263
 
264
  $_gtm_header_content = '
265
- <!-- Google Tag Manager for WordPress by DuracellTomi -->
266
  <script type="text/javascript">
267
  var gtm4wp_datalayer_name = "' . $gtm4wp_datalayer_name . '";
268
- ' . $gtm4wp_datalayer_name . ' = new Array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  </script>
270
- <!-- End Google Tag Manager -->';
271
 
272
  echo $_gtm_header_content;
273
  }
212
  function gtm4wp_enqueue_scripts() {
213
  global $gtm4wp_options, $gtp4wp_plugin_url;
214
 
215
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_OUTBOUND ] ) {
216
  wp_enqueue_script( "gtm4wp-outbound-click-tracker", $gtp4wp_plugin_url . "js/gtm4wp-outbound-click-tracker.js", array( "jquery" ), "1.0", false );
217
  }
218
 
219
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DOWNLOADS ] ) {
220
  wp_enqueue_script( "gtm4wp-download-tracker", $gtp4wp_plugin_url . "js/gtm4wp-download-tracker.js", array( "jquery" ), "1.0", false );
221
  }
222
 
223
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_EMAILCLICKS ] ) {
224
  wp_enqueue_script( "gtm4wp-email-link-tracker", $gtp4wp_plugin_url . "js/gtm4wp-email-link-tracker.js", array( "jquery" ), "1.0", false );
225
  }
226
 
227
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WPCF7 ] ) {
228
  wp_enqueue_script( "gtm4wp-contact-form-7-tracker", $gtp4wp_plugin_url . "js/gtm4wp-contact-form-7-tracker.js", array( "jquery" ), "1.0", false );
229
  }
230
 
231
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_FORMMOVE ] ) {
232
  wp_enqueue_script( "gtm4wp-form-move-tracker", $gtp4wp_plugin_url . "js/gtm4wp-form-move-tracker.js", array( "jquery" ), "1.0", false );
233
  }
234
 
235
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_SOCIAL ] ) {
236
  wp_enqueue_script( "gtm4wp-social-actions", $gtp4wp_plugin_url . "js/gtm4wp-social-tracker.js", array( "jquery" ), "1.0", false );
237
  }
238
 
239
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ] ) {
240
  require_once( dirname( __FILE__ ) . "/../integration/woocommerce.php" );
241
  wp_enqueue_script( "gtm4wp-woocommerce-tracker", $gtp4wp_plugin_url . "js/gtm4wp-woocommerce-tracker.js", array( "jquery" ), "1.0", false );
242
  }
243
+
244
+ if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
245
+ wp_enqueue_script( "gtm4wp-scroll-tracking", $gtp4wp_plugin_url . "js/analytics-talk-content-tracking.js", array( "jquery" ), "1.0", false );
246
+ }
247
  }
248
 
249
  function gtm4wp_wp_footer() {
250
  global $gtm4wp_options;
251
 
252
+ if ( GTM4WP_PLACEMENT_FOOTER == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
253
  gtm4wp_the_gtm_tag();
254
  }
255
  }
257
  function gtm4wp_wp_body_open() {
258
  global $gtm4wp_options;
259
 
260
+ if ( GTM4WP_PLACEMENT_CUSTOM == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
261
  gtm4wp_the_gtm_tag();
262
  }
263
  }
264
 
265
  function gtm4wp_wp_header() {
266
+ global $gtm4wp_datalayer_name, $gtm4wp_options;
267
 
268
  $_gtm_header_content = '
269
+ <!-- Google Tag Manager for WordPress by DuracellTomi - http://duracelltomi.com -->
270
  <script type="text/javascript">
271
  var gtm4wp_datalayer_name = "' . $gtm4wp_datalayer_name . '";
272
+ if ( "undefined" == typeof '.$gtm4wp_datalayer_name.' ) {
273
+ ' . $gtm4wp_datalayer_name . ' = new Array();
274
+ }';
275
+
276
+ if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
277
+ $_gtm_header_content .= '
278
+
279
+ var gtm4wp_scrollerscript_debugmode = ' . ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DEBUGMODE ] ? 'true' : 'false' ) . ';
280
+ var gtm4wp_scrollerscript_callbacktime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CALLBACKTIME ] . ';
281
+ var gtm4wp_scrollerscript_readerlocation = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DISTANCE ] . ';
282
+ var gtm4wp_scrollerscript_contentelementid = "' . $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CONTENTID ] . '";
283
+ var gtm4wp_scrollerscript_scannertime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_READERTIME ] . ';';
284
+ }
285
+
286
+ $_gtm_header_content .= '
287
  </script>
288
+ <!-- End Google Tag Manager for WordPress by DuracellTomi -->';
289
 
290
  echo $_gtm_header_content;
291
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: duracelltomi
3
  Donate link: http://duracelltomi.com/
4
  Tags: google tag manager, tag manager, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics
5
  Requires at least: 3.0.1
6
- Tested up to: 3.7.1
7
- Stable tag: 0.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -44,6 +44,24 @@ This plugin can fire several Tag Manager events so that you can include special
44
 
45
  Link URLs are included in the Tag Manager event so that you can use them for example in a Google Analytics event tag.
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  = Google AdWords remarketing =
48
 
49
  Google Tag Manager for WordPress can add every dataLayer variable as an AdWords remarketing custom parameter list.
@@ -69,14 +87,29 @@ More integration to come!
69
 
70
  == Frequently Asked Questions ==
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  = Can I exclude certain user roles from being tracked? =
73
 
74
  Google Tag Manager is not just about visitor tracking.
75
- The ability to include a Google/Universal Analytics tag is only one feature
76
- you can manage.
77
 
78
- Therefore there is no need to have an option to exclude the container code snippet
79
- on certain cases.
80
 
81
  If you want to exclude logged in users or certain user roles, use the corresponting dataLayer variable (visitorType)
82
  and an exclude filter in Google Tag Manager.
@@ -101,9 +134,9 @@ It can break you theme.
101
  = Why can not this plugin insert the container snippet after the opening body tag automatically? =
102
 
103
  Currently WordPress has two 'commands' or 'hooks' that a programmer can use: one for the `<head>` section and
104
- one for the bottom of `<body>`. There is no way to inject any content after the opening body tag.
105
 
106
- Fortunately some theme authors already resolved this so in some cases you do not need to edit your template files.
107
  I suggest first to select the Custom placement and use Google Tag Assistant Chrome browser extension to check
108
  whether the container code is placed as expected.
109
 
@@ -112,7 +145,7 @@ If it shows an error, go and edit your theme manually.
112
  = Facebook like/share/send button events do not fire for me, why? =
113
 
114
  It is a limitation of Facebook. Click event tracking is only available for html5/xfbml buttons.
115
- If you or your social plugin inserts the Facebook buttons using IFRAME-s (like Sociable), it is not possible to track clicks.
116
 
117
  == Screenshots ==
118
 
@@ -121,12 +154,20 @@ If you or your social plugin inserts the Facebook buttons using IFRAME-s (like S
121
  3. Events
122
  4. Integration panel
123
  5. Advanced settings
 
124
 
125
  == Changelog ==
126
 
 
 
 
 
 
 
 
127
  = 0.4 =
128
- * New: you can now select container code placement. This way you can insert the code snippet after the opening body tag. Please read FAQ for details
129
- * New: initial support for social event tracking for Facebook and Twitter buttons. Please read FAQ for details
130
  * Updated: event name on successful WooCommerce transacion: OrderCompleted -> gtm4wp.orderCompleted
131
  * Fixed: frontend JS codes did not load on some WordPress installs
132
 
@@ -154,6 +195,9 @@ If you or your social plugin inserts the Facebook buttons using IFRAME-s (like S
154
 
155
  == Upgrade Notice ==
156
 
 
 
 
157
  = 0.4 =
158
  Important change: Tag Manager event name of a WooCommerce successful order has been changed.
159
  See changelog for details.
3
  Donate link: http://duracelltomi.com/
4
  Tags: google tag manager, tag manager, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics
5
  Requires at least: 3.0.1
6
+ Tested up to: 3.8
7
+ Stable tag: 0.5
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
44
 
45
  Link URLs are included in the Tag Manager event so that you can use them for example in a Google Analytics event tag.
46
 
47
+ = Scroll tracking =
48
+
49
+ Fire tags based on how the visitor scrolls from the top to the bottom of a page.
50
+ You can track this as Analytics events and/or fire remarketing/conversion tags to if you want to track micro conversions.
51
+ Separate readers (who spend a specified amount of time on a page) from scrollers (who only scroll through within seconds)
52
+
53
+ Scroll tracking is based on the solution originally created by
54
+
55
+ * Nick Mihailovski
56
+ * Thomas Baekdal
57
+ * Avinash Kaushik
58
+ * Joost de Valk
59
+ * Eivind Savio
60
+ * Justin Cutroni
61
+
62
+ Oroginal script:
63
+ http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
64
+
65
  = Google AdWords remarketing =
66
 
67
  Google Tag Manager for WordPress can add every dataLayer variable as an AdWords remarketing custom parameter list.
87
 
88
  == Frequently Asked Questions ==
89
 
90
+ = How can I track scroll events in Google Tag Manager? =
91
+
92
+ To track scrolling of your visitor you need to setup some tag in Google Tag Manager.
93
+
94
+ What type of tags?
95
+ In most cases you will need Google/Universal Analytics event tags but you can use AdWords remarketing
96
+ or conversion tags as well to collect micro conversions or to focus only on visitors who spend more time
97
+ reading your contents.
98
+
99
+ There are five dataLayer events you can use in your rule definitions:
100
+
101
+ * gtm4wp.reading.articleLoaded: the content has been loaded
102
+ * gtm4wp.reading.startReading: the visitor started to scroll. You can use the dataLayer variable `timeToScroll` to see how many seconds have passed since the article has been loaded
103
+ * gtm4wp.reading.contentBottom: the visitor reached the end of the content (not the page!). `timeToScroll` dataLayer variable updated
104
+ * gtm4wp.reading.pagebottom: the visitor reached the end of the page. `timeToScroll` dataLayer variable updated
105
+ * gtm4wp.reading.readerType: at this point we are confident whether the visitor is a 'scanner' or 'reader' depending on how much time have passed since the content has been loaded. `readerType` dataLayer variable holds the type of the visitor
106
+
107
  = Can I exclude certain user roles from being tracked? =
108
 
109
  Google Tag Manager is not just about visitor tracking.
110
+ The ability to include a Google/Universal Analytics tag is only one feature you can manage.
 
111
 
112
+ Therefore there is no need to have an option to exclude the container code snippet on certain cases.
 
113
 
114
  If you want to exclude logged in users or certain user roles, use the corresponting dataLayer variable (visitorType)
115
  and an exclude filter in Google Tag Manager.
134
  = Why can not this plugin insert the container snippet after the opening body tag automatically? =
135
 
136
  Currently WordPress has two 'commands' or 'hooks' that a programmer can use: one for the `<head>` section and
137
+ one for the bottom of `<body>`. There is no way to inject any content after the opening body tag without manually editing your template files.
138
 
139
+ Fortunately some theme authors already resolved this so in some cases you do not need to edit your template.
140
  I suggest first to select the Custom placement and use Google Tag Assistant Chrome browser extension to check
141
  whether the container code is placed as expected.
142
 
145
  = Facebook like/share/send button events do not fire for me, why? =
146
 
147
  It is a limitation of Facebook. Click event tracking is only available for html5/xfbml buttons.
148
+ If you or your social plugin inserts the Facebook buttons using IFRAME-s (like Sociable), it is not possible to track likes.
149
 
150
  == Screenshots ==
151
 
154
  3. Events
155
  4. Integration panel
156
  5. Advanced settings
157
+ 6. Scroll tracking
158
 
159
  == Changelog ==
160
 
161
+ = 0.5 =
162
+ * Added: scroll tracking
163
+ * Fixed: social tracking option on the admin panel was being shown as an edit box instead of a checbox
164
+ * Fixed: WooCommerce transaction data was not included in the dataLayer if you selected "Custom" code placement
165
+ * Fixed: do not do anything if you enabled WooCommerce integration but did not activate WooCommerce plugin itself
166
+ * Updated: do not re-declare dataLayer variable if it already exists (because another script already created it before my plugin was run)
167
+
168
  = 0.4 =
169
+ * Added: you can now select container code placement. This way you can insert the code snippet after the opening body tag. Please read FAQ for details
170
+ * Added: initial support for social event tracking for Facebook and Twitter buttons. Please read FAQ for details
171
  * Updated: event name on successful WooCommerce transacion: OrderCompleted -> gtm4wp.orderCompleted
172
  * Fixed: frontend JS codes did not load on some WordPress installs
173
 
195
 
196
  == Upgrade Notice ==
197
 
198
+ = 0.5 =
199
+ Besides of some fixes this version includes scroll tracking events for Google Tag Manager.
200
+
201
  = 0.4 =
202
  Important change: Tag Manager event name of a WooCommerce successful order has been changed.
203
  See changelog for details.