Version Description
- Updated: admin page does not show an alert box if Tag Manager ID or dataLayer variable name is incorrect. Instead it shows a warning line below the input field.
- Updated: rewritten the code for WooCommerce dynamic remarketing. Added tag for homepage and order completed page.
Download this release
Release Info
Developer | duracelltomi |
Plugin | DuracellTomi's Google Tag Manager for WordPress |
Version | 0.3 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.3
- admin/admin.php +21 -4
- duracelltomi-google-tag-manager-for-wordpress.php +2 -2
- integration/woocommerce.php +47 -53
- readme.txt +10 -3
admin/admin.php
CHANGED
@@ -145,12 +145,14 @@ function gtm4wp_admin_output_field( $args ) {
|
|
145 |
switch( $args["label_for"] ) {
|
146 |
case GTM4WP_ADMIN_GROUP_GTMID: {
|
147 |
echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" value="' . $gtm4wp_options[GTM4WP_OPTION_GTM_CODE] . '" /><br />' . $args["description"];
|
|
|
148 |
|
149 |
break;
|
150 |
}
|
151 |
|
152 |
case GTM4WP_ADMIN_GROUP_DATALAYER: {
|
153 |
echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']" value="' . $gtm4wp_options[GTM4WP_OPTION_DATALAYER_NAME] . '" /><br />' . $args["description"];
|
|
|
154 |
|
155 |
break;
|
156 |
}
|
@@ -401,26 +403,41 @@ function gtm4wp_add_admin_js($hook) {
|
|
401 |
|
402 |
function gtm4wp_admin_head() {
|
403 |
echo '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
<script type="text/javascript">
|
405 |
jQuery(function() {
|
406 |
jQuery( "#gtm4wp-options\\\\[gtm-code\\\\]" )
|
407 |
.bind( "blur", function() {
|
408 |
var gtmid_regex = /^GTM-[A-Z0-9]+$/;
|
409 |
if ( ! gtmid_regex.test( jQuery( this ).val() ) ) {
|
410 |
-
|
411 |
-
|
|
|
|
|
|
|
412 |
}
|
413 |
});
|
414 |
|
415 |
jQuery( "#gtm4wp-options\\\\[gtm-datalayer-variable-name\\\\]" )
|
416 |
.bind( "blur", function() {
|
417 |
var currentval = jQuery( this ).val();
|
|
|
|
|
|
|
|
|
418 |
if ( currentval != "" ) {
|
419 |
// I know this is not the exact definition for a variable name but I think other kind of variable names should not be used.
|
420 |
var gtmvarname_regex = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
421 |
if ( ! gtmvarname_regex.test( currentval ) ) {
|
422 |
-
|
423 |
-
|
424 |
}
|
425 |
}
|
426 |
});
|
145 |
switch( $args["label_for"] ) {
|
146 |
case GTM4WP_ADMIN_GROUP_GTMID: {
|
147 |
echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']" value="' . $gtm4wp_options[GTM4WP_OPTION_GTM_CODE] . '" /><br />' . $args["description"];
|
148 |
+
echo '<br /><span class="gtmid_validation_error">' . __( "This does not seems to be a valid Google Tag Manager ID! Please check and try again", GTM4WP_TEXTDOMAIN ) . '</span>';
|
149 |
|
150 |
break;
|
151 |
}
|
152 |
|
153 |
case GTM4WP_ADMIN_GROUP_DATALAYER: {
|
154 |
echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']" value="' . $gtm4wp_options[GTM4WP_OPTION_DATALAYER_NAME] . '" /><br />' . $args["description"];
|
155 |
+
echo '<br /><span class="datalayername_validation_error">' . __( "This does not seems to be a valid JavaScript variable name! Please check and try again", GTM4WP_TEXTDOMAIN ) . '</span>';
|
156 |
|
157 |
break;
|
158 |
}
|
403 |
|
404 |
function gtm4wp_admin_head() {
|
405 |
echo '
|
406 |
+
<style type="text/css">
|
407 |
+
.gtmid_validation_error,
|
408 |
+
.datalayername_validation_error {
|
409 |
+
display: none;
|
410 |
+
color: #c00;
|
411 |
+
font-weight: bold;
|
412 |
+
}
|
413 |
+
</style>
|
414 |
<script type="text/javascript">
|
415 |
jQuery(function() {
|
416 |
jQuery( "#gtm4wp-options\\\\[gtm-code\\\\]" )
|
417 |
.bind( "blur", function() {
|
418 |
var gtmid_regex = /^GTM-[A-Z0-9]+$/;
|
419 |
if ( ! gtmid_regex.test( jQuery( this ).val() ) ) {
|
420 |
+
jQuery( ".gtmid_validation_error" )
|
421 |
+
.show();
|
422 |
+
} else {
|
423 |
+
jQuery( ".gtmid_validation_error" )
|
424 |
+
.hide();
|
425 |
}
|
426 |
});
|
427 |
|
428 |
jQuery( "#gtm4wp-options\\\\[gtm-datalayer-variable-name\\\\]" )
|
429 |
.bind( "blur", function() {
|
430 |
var currentval = jQuery( this ).val();
|
431 |
+
|
432 |
+
jQuery( ".datalayername_validation_error" )
|
433 |
+
.hide();
|
434 |
+
|
435 |
if ( currentval != "" ) {
|
436 |
// I know this is not the exact definition for a variable name but I think other kind of variable names should not be used.
|
437 |
var gtmvarname_regex = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
438 |
if ( ! gtmvarname_regex.test( currentval ) ) {
|
439 |
+
jQuery( ".datalayername_validation_error" )
|
440 |
+
.show();
|
441 |
}
|
442 |
}
|
443 |
});
|
duracelltomi-google-tag-manager-for-wordpress.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: DuracellTomi's Google Tag Manager for Wordpress
|
4 |
-
Version: 0.
|
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.
|
12 |
define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
|
13 |
define( 'GTM4WP_TEXTDOMAIN', 'gtm4wp-lang' );
|
14 |
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: DuracellTomi's Google Tag Manager for Wordpress
|
4 |
+
Version: 0.3
|
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.3' );
|
12 |
define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
|
13 |
define( 'GTM4WP_TEXTDOMAIN', 'gtm4wp-lang' );
|
14 |
|
integration/woocommerce.php
CHANGED
@@ -21,6 +21,8 @@ function gtm4wp_woocommerce_datalayer_filter_order( $dataLayer ) {
|
|
21 |
$dataLayer["transactionPromoCode"] = implode( ", ", $order->get_used_coupons() );
|
22 |
|
23 |
$_products = array();
|
|
|
|
|
24 |
|
25 |
if ( $order->get_items() ) {
|
26 |
foreach ( $order->get_items() as $item ) {
|
@@ -42,22 +44,29 @@ function gtm4wp_woocommerce_datalayer_filter_order( $dataLayer ) {
|
|
42 |
$_category = implode( " / ", $out );
|
43 |
}
|
44 |
|
|
|
45 |
$_products[] = array(
|
46 |
"id" => $_product->id,
|
47 |
"name" => $item['name'],
|
48 |
"sku" => $_product->get_sku() ? __( 'SKU:', GTM4WP_TEXTDOMAIN ) . ' ' . $_product->get_sku() : $_product->id,
|
49 |
"category" => $_category,
|
50 |
-
"price" => $
|
51 |
"currency" => get_woocommerce_currency(),
|
52 |
"quantity" => $item['qty']
|
53 |
);
|
|
|
|
|
|
|
54 |
}
|
55 |
}
|
56 |
|
57 |
$dataLayer["transactionProducts"] = $_products;
|
58 |
-
|
59 |
$dataLayer["event"] = "OrderCompleted";
|
60 |
|
|
|
|
|
|
|
|
|
61 |
return $dataLayer;
|
62 |
}
|
63 |
|
@@ -74,64 +83,49 @@ function gtm4wp_woocommerce_thankyou( $order_id ) {
|
|
74 |
update_post_meta( $order_id, '_ga_tracked', 1 );
|
75 |
}
|
76 |
|
77 |
-
function gtm4wp_woocommerce_before_shop_loop_item() {
|
78 |
-
global $product, $gtp4wp_woocommerce_remarketing_sku_list, $gtp4wp_woocommerce_remarketing_totalvalue;
|
79 |
-
|
80 |
-
if ( is_product() ) {
|
81 |
-
return;
|
82 |
-
}
|
83 |
-
|
84 |
-
$_sku = $product->get_sku();
|
85 |
-
if ( "" == $_sku ) {
|
86 |
-
$_sku = $product->id;
|
87 |
-
}
|
88 |
-
|
89 |
-
$gtp4wp_woocommerce_remarketing_sku_list[] = $_sku;
|
90 |
-
$gtp4wp_woocommerce_remarketing_totalvalue += $product->get_price();
|
91 |
-
}
|
92 |
-
|
93 |
-
function gtm4wp_woocommerce_before_single_product() {
|
94 |
-
global $product, $related, $gtp4wp_woocommerce_remarketing_sku_list, $gtp4wp_woocommerce_remarketing_totalvalue;
|
95 |
-
|
96 |
-
if ( ! is_product() ) {
|
97 |
-
return;
|
98 |
-
}
|
99 |
-
|
100 |
-
$_sku = $product->get_sku();
|
101 |
-
if ( "" == $_sku ) {
|
102 |
-
$_sku = $product->id;
|
103 |
-
}
|
104 |
-
|
105 |
-
$gtp4wp_woocommerce_remarketing_sku_list[] = $_sku;
|
106 |
-
$gtp4wp_woocommerce_remarketing_totalvalue += $product->get_price();
|
107 |
-
}
|
108 |
-
|
109 |
function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
110 |
-
global $gtp4wp_woocommerce_remarketing_sku_list, $gtp4wp_woocommerce_remarketing_totalvalue;
|
111 |
-
|
112 |
-
if (
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
|
131 |
return $dataLayer;
|
132 |
}
|
133 |
|
134 |
add_action( "woocommerce_thankyou", "gtm4wp_woocommerce_thankyou" );
|
135 |
-
add_action( "woocommerce_before_shop_loop_item", "gtm4wp_woocommerce_before_shop_loop_item" );
|
136 |
-
add_action( "woocommerce_before_single_product", "gtm4wp_woocommerce_before_single_product" );
|
137 |
add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_items" );
|
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 ) {
|
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 += $item['qty'] * $_prodprice;
|
59 |
+
$_product_ids[] = "'" . $_product->id . "'";
|
60 |
}
|
61 |
}
|
62 |
|
63 |
$dataLayer["transactionProducts"] = $_products;
|
|
|
64 |
$dataLayer["event"] = "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 |
|
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"] = "";
|
91 |
+
$dataLayer["ecomm_pagetype"] = "home";
|
92 |
+
$dataLayer["ecomm_totalvalue"] = 0;
|
93 |
+
} else if ( is_product_category() || is_product_tag() ) {
|
94 |
+
$sumprice = 0;
|
95 |
+
$product_ids = array();
|
96 |
+
foreach ( $woocommerce->query->filtered_product_ids as $oneproductid ) {
|
97 |
+
$product = get_product( $oneproductid );
|
98 |
+
$sumprice += $product->get_price();
|
99 |
+
$product_ids[] = "'" . $oneproductid . "'";
|
100 |
}
|
101 |
+
|
102 |
+
$dataLayer["ecomm_prodid"] = '[' . implode( ", ", $product_ids ) . ']';
|
103 |
+
$dataLayer["ecomm_pagetype"] = "category";
|
104 |
+
$dataLayer["ecomm_totalvalue"] = $sumprice;
|
105 |
+
} else if ( is_product() ) {
|
106 |
+
$prodid = get_the_ID();
|
107 |
+
$product = get_product( $prodid );
|
108 |
+
$product_price = $product->get_price();
|
109 |
+
|
110 |
+
$dataLayer["ecomm_prodid"] = $prodid;
|
111 |
+
$dataLayer["ecomm_pagetype"] = "product";
|
112 |
+
$dataLayer["ecomm_totalvalue"] = $product_price;
|
113 |
+
} else if ( is_cart() ) {
|
114 |
+
$products = $woocommerce->cart->get_cart();
|
115 |
+
$product_ids = array();
|
116 |
+
foreach( $products as $oneproduct ) {
|
117 |
+
$product_ids[] = "'" . str_replace( "'", "\\'", $oneproduct['product_id'] ) . "'";
|
118 |
}
|
119 |
+
|
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" );
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== DuracellTomi's Google Tag Manager for WordPress ===
|
2 |
Contributors: duracelltomi
|
3 |
Donate link: http://duracelltomi.com/
|
4 |
-
Tags: google tag manager, tag manager, google, adwords, google adwords, adwords remarketing, remarketing
|
5 |
Requires at least: 3.0.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 0.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
@@ -89,6 +89,10 @@ and an exclude filter in Google Tag Manager.
|
|
89 |
|
90 |
== Changelog ==
|
91 |
|
|
|
|
|
|
|
|
|
92 |
= 0.2 =
|
93 |
* ! BACKWARD INCOMPATIBLE CHANGE ! - Names of Tag Manager click events has been changed to comply with naming conventions:
|
94 |
* ContactFormSubmitted -> gtm4wp.contactForm7Submitted
|
@@ -109,6 +113,9 @@ and an exclude filter in Google Tag Manager.
|
|
109 |
|
110 |
== Upgrade Notice ==
|
111 |
|
|
|
|
|
|
|
112 |
= 0.2 =
|
113 |
BACKWARD INCOMPATIBLE CHANGE: Names of Tag Manager click events has been changed to comply naming conventions.
|
114 |
See changelog for details. Do not forget to update your Tag Manager container setup after upgrading this plugin!
|
1 |
=== DuracellTomi's Google Tag Manager for WordPress ===
|
2 |
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.3
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
89 |
|
90 |
== Changelog ==
|
91 |
|
92 |
+
= 0.3 =
|
93 |
+
* Updated: admin page does not show an alert box if Tag Manager ID or dataLayer variable name is incorrect. Instead it shows a warning line below the input field.
|
94 |
+
* Updated: rewritten the code for WooCommerce dynamic remarketing. Added tag for homepage and order completed page.
|
95 |
+
|
96 |
= 0.2 =
|
97 |
* ! BACKWARD INCOMPATIBLE CHANGE ! - Names of Tag Manager click events has been changed to comply with naming conventions:
|
98 |
* ContactFormSubmitted -> gtm4wp.contactForm7Submitted
|
113 |
|
114 |
== Upgrade Notice ==
|
115 |
|
116 |
+
= 0.3 =
|
117 |
+
This is a minor release. If you are using WooCommerce you should update to include more accurate adwords dynamic remarketing feature.
|
118 |
+
|
119 |
= 0.2 =
|
120 |
BACKWARD INCOMPATIBLE CHANGE: Names of Tag Manager click events has been changed to comply naming conventions.
|
121 |
See changelog for details. Do not forget to update your Tag Manager container setup after upgrading this plugin!
|