Version Description
- Updated: even better WooCommerce 3.0 compatibility (WooCommerce 2.6 still supported but this support ends with the next plugin version)
- Fixed: properly escaping product category name on variable product detail pages
- Fixed: proper data layer stucture in the gtm4wp.changeDetailViewEEC event
- Added: Google Optimize page hiding snippet under Integrations tab
- Added: add to cart data for WooCommerce enhanced ecommerce tracking if user undos a cart item removal (no need to update GTM tags)
- Added: you can now enter a product ID prefix so that IDs can match with IDs in some product feeds generated by other plugins
- Added: option to track cart page as step 1 in enhanced ecommerce checkout funnel
Download this release
Release Info
Developer | duracelltomi |
Plugin | DuracellTomi's Google Tag Manager for WordPress |
Version | 1.7 |
Comparing to | |
See all releases |
Code changes from version 1.6.1 to 1.7
- admin/admin.php +117 -56
- common/readoptions.php +19 -9
- duracelltomi-google-tag-manager-for-wordpress.php +2 -2
- integration/google-optimize.php +28 -0
- integration/woocommerce.php +166 -51
- js/admin-subtabs.js +4 -0
- public/frontend.php +6 -2
- readme.txt +19 -5
admin/admin.php
CHANGED
@@ -72,11 +72,11 @@ $GLOBALS["gtm4wp_includefieldtexts"] = array(
|
|
72 |
"description" => __( "Check this option to include the count of the posts currently shown on the page and the total number of posts in the category/tag/any taxonomy.", 'duracelltomi-google-tag-manager' ),
|
73 |
"phase" => GTM4WP_PHASE_STABLE
|
74 |
),
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
GTM4WP_OPTION_INCLUDE_SEARCHDATA => array(
|
81 |
"label" => __( "Search data", 'duracelltomi-google-tag-manager' ),
|
82 |
"description" => __( "Check this option to include the search term, referring page URL and number of results on the search page.", 'duracelltomi-google-tag-manager' ),
|
@@ -398,13 +398,6 @@ $GLOBALS["gtm4wp_integratefieldtexts"] = array(
|
|
398 |
"phase" => GTM4WP_PHASE_STABLE,
|
399 |
"plugintocheck" => "contact-form-7/wp-contact-form-7.php"
|
400 |
),
|
401 |
-
/*
|
402 |
-
GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE => array(
|
403 |
-
"label" => __( "WooCommerce", 'duracelltomi-google-tag-manager' ),
|
404 |
-
"description" => __( "Enable this and you will get:<br /> - Add-to-cart events<br /> - E-commerce transaction data ready to be used with Google Analytics and Universal Analytics tags<br /> - Google AdWords dynamic remarketing tags", 'duracelltomi-google-tag-manager' ),
|
405 |
-
"plugintocheck" => "woocommerce/woocommerce.php"
|
406 |
-
)
|
407 |
-
*/
|
408 |
GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => array(
|
409 |
"label" => __( "Track classic e-commerce", 'duracelltomi-google-tag-manager' ),
|
410 |
"description" => __( sprintf( __( "Choose this option if you would like to track e-commerce data using <a href=\"%s\" target=\"_blank\">classic transaction data</a>.", 'duracelltomi-google-tag-manager' ) , 'https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce'), 'duracelltomi-google-tag-manager' ),
|
@@ -417,17 +410,41 @@ $GLOBALS["gtm4wp_integratefieldtexts"] = array(
|
|
417 |
"phase" => GTM4WP_PHASE_BETA,
|
418 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
419 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
GTM4WP_OPTION_INTEGRATE_WCREMARKETING => array(
|
421 |
"label" => __( "AdWords Remarketing", 'duracelltomi-google-tag-manager' ),
|
422 |
"description" => __( "Enable this to add Google AdWords dynamic remarketing variables to the dataLayer", 'duracelltomi-google-tag-manager' ),
|
423 |
"phase" => GTM4WP_PHASE_STABLE,
|
424 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
425 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
GTM4WP_OPTION_INTEGRATE_WCUSESKU => array(
|
427 |
"label" => __( "Use SKU instead of ID", 'duracelltomi-google-tag-manager' ),
|
428 |
"description" => __( "Check this to use product SKU instead of the ID of the products for remarketing and ecommerce tracking. Will fallback to ID if no SKU is set.", 'duracelltomi-google-tag-manager' ),
|
429 |
-
"phase" =>
|
430 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
)
|
432 |
);
|
433 |
|
@@ -438,7 +455,7 @@ function gtm4wp_admin_output_section( $args ) {
|
|
438 |
case GTM4WP_ADMIN_GROUP_GENERAL: {
|
439 |
_e( 'This plugin is intended to be used by IT girls&guys and marketing staff. Please be sure you read the <a href="https://developers.google.com/tag-manager/" target="_blank">Google Tag Manager Help Center</a> before you start using this plugin.<br /><br />', 'duracelltomi-google-tag-manager' );
|
440 |
|
441 |
-
break;
|
442 |
}
|
443 |
|
444 |
case GTM4WP_ADMIN_GROUP_INCLUDES: {
|
@@ -450,7 +467,7 @@ function gtm4wp_admin_output_section( $args ) {
|
|
450 |
_e( 'You are using an <strong>outdated</strong> version of PHP (5.3 or less). You <strong>should not turn on</strong> browser/device/os tracking as this can hurt your site. Please talk to your hosting and upgrade to PHP 5.4 or newer.', 'duracelltomi-google-tag-manager' );
|
451 |
}
|
452 |
|
453 |
-
break;
|
454 |
}
|
455 |
|
456 |
case GTM4WP_ADMIN_GROUP_EVENTS: {
|
@@ -459,7 +476,7 @@ function gtm4wp_admin_output_section( $args ) {
|
|
459 |
_e( 'In October 2013 Google released a new feature called <a href="https://support.google.com/tagmanager/answer/3415369?hl=en" target="_blank">auto event tracking</a>. It is up to you how you use click events either using Google\'s solution or the settings below.', 'duracelltomi-google-tag-manager' );
|
460 |
echo '</p>';
|
461 |
|
462 |
-
break;
|
463 |
}
|
464 |
|
465 |
case GTM4WP_ADMIN_GROUP_SCROLLER: {
|
@@ -467,7 +484,7 @@ function gtm4wp_admin_output_section( $args ) {
|
|
467 |
echo '<br />';
|
468 |
printf( __( 'Based on the script originaly posted to <a href="%s">Analytics Talk</a>', 'duracelltomi-google-tag-manager' ) , "http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/");
|
469 |
|
470 |
-
break;
|
471 |
}
|
472 |
|
473 |
case GTM4WP_ADMIN_GROUP_BLACKLIST: {
|
@@ -479,28 +496,28 @@ function gtm4wp_admin_output_section( $args ) {
|
|
479 |
echo '<br />';
|
480 |
_e( "Uncheck a row to blacklist a macro type.", 'duracelltomi-google-tag-manager' );
|
481 |
|
482 |
-
break;
|
483 |
}
|
484 |
|
485 |
case GTM4WP_ADMIN_GROUP_INTEGRATION: {
|
486 |
_e( "Google Tag Manager for WordPress can integrate with several popular plugins. Please check the plugins you would like to integrate with:", 'duracelltomi-google-tag-manager' );
|
487 |
|
488 |
-
break;
|
489 |
}
|
490 |
|
491 |
case GTM4WP_ADMIN_GROUP_ADVANCED: {
|
492 |
_e( "You usually do not need to modify thoose settings. Please be carefull while hacking here.", 'duracelltomi-google-tag-manager' );
|
493 |
|
494 |
-
break;
|
495 |
}
|
496 |
|
497 |
case GTM4WP_ADMIN_GROUP_CREDITS: {
|
498 |
_e( "Some info about the author of this plugin", 'duracelltomi-google-tag-manager' );
|
499 |
|
500 |
-
break;
|
501 |
}
|
502 |
} // end switch
|
503 |
-
|
504 |
echo '</span>';
|
505 |
}
|
506 |
|
@@ -511,7 +528,7 @@ function gtm4wp_admin_output_field( $args ) {
|
|
511 |
case GTM4WP_ADMIN_GROUP_GTMID: {
|
512 |
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"];
|
513 |
echo '<br /><span class="gtmid_validation_error">' . __( "This does not seems to be a valid Google Tag Manager ID! Valid format: GTM-XXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile container IDs.", 'duracelltomi-google-tag-manager' ) . '</span>';
|
514 |
-
|
515 |
break;
|
516 |
}
|
517 |
|
@@ -523,14 +540,14 @@ function gtm4wp_admin_output_field( $args ) {
|
|
523 |
|
524 |
break;
|
525 |
}
|
526 |
-
|
527 |
case GTM4WP_ADMIN_GROUP_DATALAYER: {
|
528 |
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"];
|
529 |
echo '<br /><span class="datalayername_validation_error">' . __( "This does not seems to be a valid JavaScript variable name! Please check and try again", 'duracelltomi-google-tag-manager' ) . '</span>';
|
530 |
|
531 |
break;
|
532 |
}
|
533 |
-
|
534 |
case GTM4WP_OPTIONS . "[" . GTM4WP_OPTION_BLACKLIST_ENABLE . "]": {
|
535 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="0" ' . ( $gtm4wp_options[GTM4WP_OPTION_BLACKLIST_ENABLE] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( "Disable feature: control everything on Google Tag Manager interface", 'duracelltomi-google-tag-manager' ) . '<br />';
|
536 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="1" ' . ( $gtm4wp_options[GTM4WP_OPTION_BLACKLIST_ENABLE] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( "Allow all, except the checked items below (blacklist)", 'duracelltomi-google-tag-manager' ) . '<br />';
|
@@ -539,7 +556,7 @@ function gtm4wp_admin_output_field( $args ) {
|
|
539 |
|
540 |
break;
|
541 |
}
|
542 |
-
|
543 |
case GTM4WP_OPTIONS . "[" . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . "]": {
|
544 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']" value="0" ' . ( $gtm4wp_options[GTM4WP_OPTION_INCLUDE_WEATHERUNITS] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( "Celsius", 'duracelltomi-google-tag-manager' ) . '<br />';
|
545 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']" value="1" ' . ( $gtm4wp_options[GTM4WP_OPTION_INCLUDE_WEATHERUNITS] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( "Fahrenheit", 'duracelltomi-google-tag-manager' ) . '<br />';
|
@@ -601,7 +618,7 @@ function gtm4wp_admin_output_field( $args ) {
|
|
601 |
|
602 |
function gtm4wp_sanitize_options($options) {
|
603 |
global $wpdb;
|
604 |
-
|
605 |
$output = gtm4wp_reload_options();
|
606 |
|
607 |
foreach($output as $optionname => $optionvalue) {
|
@@ -634,6 +651,32 @@ function gtm4wp_sanitize_options($options) {
|
|
634 |
}
|
635 |
}
|
636 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
// integrations
|
638 |
} else if ( substr($optionname, 0, 10) == "integrate-" ) {
|
639 |
$output[$optionname] = (boolean) $newoptionvalue;
|
@@ -641,9 +684,7 @@ function gtm4wp_sanitize_options($options) {
|
|
641 |
// GTM code or dataLayer variable name
|
642 |
} else if ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) ) {
|
643 |
$newoptionvalue = trim($newoptionvalue);
|
644 |
-
|
645 |
-
// if ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) && ( ! preg_match( "/^GTM-[A-Z0-9]+$/", $newoptionvalue ) ) ) {
|
646 |
-
// add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']', __( "Invalid Google Tag Manager ID. Valid ID format: GTM-XXXXX", 'duracelltomi-google-tag-manager' ) );
|
647 |
if ( $optionname == GTM4WP_OPTION_GTM_CODE ) {
|
648 |
$_gtmid_list = explode( ",", $newoptionvalue );
|
649 |
$_gtmid_haserror = false;
|
@@ -674,6 +715,7 @@ function gtm4wp_sanitize_options($options) {
|
|
674 |
// scroll tracking content ID
|
675 |
} else if ( $optionname == GTM4WP_OPTION_SCROLLER_CONTENTID ) {
|
676 |
$output[$optionname] = trim( str_replace( "#", "", $newoptionvalue ) );
|
|
|
677 |
// anything else
|
678 |
} else {
|
679 |
switch( gettype($optionvalue)) {
|
@@ -695,23 +737,23 @@ function gtm4wp_sanitize_options($options) {
|
|
695 |
} // end switch
|
696 |
}
|
697 |
}
|
698 |
-
|
699 |
return $output;
|
700 |
}
|
701 |
|
702 |
function gtm4wp_admin_init() {
|
703 |
global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts,
|
704 |
$gtm4wp_blacklistfieldtexts, $gtm4wp_blacklistmfieldtexts;
|
705 |
-
|
706 |
register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, "gtm4wp_sanitize_options" );
|
707 |
-
|
708 |
add_settings_section(
|
709 |
GTM4WP_ADMIN_GROUP_GENERAL,
|
710 |
__( 'General', 'duracelltomi-google-tag-manager' ),
|
711 |
'gtm4wp_admin_output_section',
|
712 |
GTM4WP_ADMINSLUG
|
713 |
);
|
714 |
-
|
715 |
add_settings_field(
|
716 |
GTM4WP_ADMIN_GROUP_GTMID,
|
717 |
__( 'Google Tag Manager ID', 'duracelltomi-google-tag-manager' ),
|
@@ -742,7 +784,7 @@ function gtm4wp_admin_init() {
|
|
742 |
'gtm4wp_admin_output_section',
|
743 |
GTM4WP_ADMINSLUG
|
744 |
);
|
745 |
-
|
746 |
foreach($gtm4wp_includefieldtexts as $fieldid => $fielddata) {
|
747 |
add_settings_field(
|
748 |
"gtm4wp-admin-" . $fieldid . "-id",
|
@@ -764,7 +806,7 @@ function gtm4wp_admin_init() {
|
|
764 |
'gtm4wp_admin_output_section',
|
765 |
GTM4WP_ADMINSLUG
|
766 |
);
|
767 |
-
|
768 |
foreach($gtm4wp_eventfieldtexts as $fieldid => $fielddata) {
|
769 |
add_settings_field(
|
770 |
"gtm4wp-admin-" . $fieldid . "-id",
|
@@ -786,7 +828,7 @@ function gtm4wp_admin_init() {
|
|
786 |
'gtm4wp_admin_output_section',
|
787 |
GTM4WP_ADMINSLUG
|
788 |
);
|
789 |
-
|
790 |
foreach($gtm4wp_scrollerfieldtexts as $fieldid => $fielddata) {
|
791 |
add_settings_field(
|
792 |
"gtm4wp-admin-" . $fieldid . "-id",
|
@@ -808,7 +850,7 @@ function gtm4wp_admin_init() {
|
|
808 |
'gtm4wp_admin_output_section',
|
809 |
GTM4WP_ADMINSLUG
|
810 |
);
|
811 |
-
|
812 |
foreach($gtm4wp_blacklistfieldtexts as $fieldid => $fielddata) {
|
813 |
add_settings_field(
|
814 |
"gtm4wp-admin-" . $fieldid . "-id",
|
@@ -857,7 +899,7 @@ function gtm4wp_admin_init() {
|
|
857 |
"label_for" => "gtm4wp-options[" . $fieldid . "]",
|
858 |
"description" => $fielddata["description"],
|
859 |
"optionfieldid" => $fieldid,
|
860 |
-
"plugintocheck" => $fielddata["plugintocheck"]
|
861 |
)
|
862 |
);
|
863 |
}
|
@@ -952,6 +994,7 @@ function gtm4wp_add_admin_js($hook) {
|
|
952 |
"blockmacrostabtitle" => __( "Blacklist macros" , 'duracelltomi-google-tag-manager' ),
|
953 |
"wpcf7tabtitle" => __( "Contact Form 7" , 'duracelltomi-google-tag-manager' ),
|
954 |
"wctabtitle" => __( "WooCommerce" , 'duracelltomi-google-tag-manager' ),
|
|
|
955 |
"weathertabtitle" => __( "Weather data" , 'duracelltomi-google-tag-manager' ),
|
956 |
"generaleventstabtitle" => __( "General events" , 'duracelltomi-google-tag-manager' ),
|
957 |
"mediaeventstabtitle" => __( "Media events" , 'duracelltomi-google-tag-manager' ),
|
@@ -971,6 +1014,7 @@ function gtm4wp_admin_head() {
|
|
971 |
echo '
|
972 |
<style type="text/css">
|
973 |
.gtmid_validation_error,
|
|
|
974 |
.datalayername_validation_error {
|
975 |
display: none;
|
976 |
color: #c00;
|
@@ -982,7 +1026,7 @@ function gtm4wp_admin_head() {
|
|
982 |
jQuery( "#gtm4wp-options\\\\[gtm-code\\\\]" )
|
983 |
.bind( "blur", function() {
|
984 |
var gtmid_regex = /^GTM-[A-Z0-9]+$/;
|
985 |
-
var gtmid_list = jQuery( this ).val().split( "," );
|
986 |
|
987 |
var gtmid_haserror = false;
|
988 |
for( var i=0; i<gtmid_list.length; i++ ) {
|
@@ -998,6 +1042,30 @@ function gtm4wp_admin_head() {
|
|
998 |
}
|
999 |
});
|
1000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1001 |
jQuery( "#gtm4wp-options\\\\[gtm-datalayer-variable-name\\\\]" )
|
1002 |
.bind( "blur", function() {
|
1003 |
var currentval = jQuery( this ).val();
|
@@ -1015,20 +1083,13 @@ function gtm4wp_admin_head() {
|
|
1015 |
}
|
1016 |
});
|
1017 |
|
1018 |
-
jQuery(
|
1019 |
-
.
|
1020 |
-
e.preventDefault();
|
1021 |
-
|
1022 |
jQuery.post(ajaxurl, {
|
1023 |
action: "gtm4wp_dismiss_notice",
|
1024 |
-
noticeid: jQuery( this )
|
1025 |
-
.attr( "href" )
|
1026 |
.substring( 1 )
|
1027 |
-
}, function ( response ) {
|
1028 |
-
jQuery( ".gtm4wp-dismiss-notice" )
|
1029 |
-
.parent()
|
1030 |
-
.parent()
|
1031 |
-
.fadeOut( "slow" );
|
1032 |
});
|
1033 |
});
|
1034 |
});
|
@@ -1051,7 +1112,7 @@ function gtm4wp_show_warning() {
|
|
1051 |
$gtm4wp_user_notices_dismisses = array_merge( $gtm4wp_def_user_notices_dismisses, $gtm4wp_user_notices_dismisses );
|
1052 |
|
1053 |
if ( ( trim( $gtm4wp_options[GTM4WP_OPTION_GTM_CODE] ) == "" ) && ( false === $gtm4wp_user_notices_dismisses["enter-gtm-code"] ) ) {
|
1054 |
-
echo '<div
|
1055 |
}
|
1056 |
|
1057 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-ga-plugin-warning"] ) || ( false === $gtm4wp_user_notices_dismisses["wc-gayoast-plugin-warning"] ) || ( false === $gtm4wp_user_notices_dismisses["wc-1-3-upgrade-info"] ) ) {
|
@@ -1063,21 +1124,21 @@ function gtm4wp_show_warning() {
|
|
1063 |
$woo_ga_options = get_option( "woocommerce_google_analytics_settings" );
|
1064 |
if ( $woo_ga_options ) {
|
1065 |
if ( "" != $woo_ga_options["ga_id"] ) {
|
1066 |
-
echo '<div
|
1067 |
}
|
1068 |
}
|
1069 |
}
|
1070 |
|
1071 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-ga-plugin-warning"] ) && $is_wc_active && is_plugin_active( "woocommerce-google-analytics-integration/woocommerce-google-analytics-integration.php" ) ) {
|
1072 |
-
echo '<div
|
1073 |
}
|
1074 |
|
1075 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-gayoast-plugin-warning"] ) && $is_wc_active && is_plugin_active( "google-analytics-for-wordpress/googleanalytics.php" ) ) {
|
1076 |
-
echo '<div
|
1077 |
}
|
1078 |
|
1079 |
if ( $is_wc_active && ( false === $gtm4wp_user_notices_dismisses["wc-1-3-upgrade-info"] ) ) {
|
1080 |
-
echo '<div
|
1081 |
}
|
1082 |
}
|
1083 |
}
|
72 |
"description" => __( "Check this option to include the count of the posts currently shown on the page and the total number of posts in the category/tag/any taxonomy.", 'duracelltomi-google-tag-manager' ),
|
73 |
"phase" => GTM4WP_PHASE_STABLE
|
74 |
),
|
75 |
+
GTM4WP_OPTION_INCLUDE_POSTID => array(
|
76 |
+
"label" => __( "Post ID", 'duracelltomi-google-tag-manager' ),
|
77 |
+
"description" => __( "Check this option to include the post id.", 'duracelltomi-google-tag-manager' ),
|
78 |
+
"phase" => GTM4WP_PHASE_STABLE
|
79 |
+
),
|
80 |
GTM4WP_OPTION_INCLUDE_SEARCHDATA => array(
|
81 |
"label" => __( "Search data", 'duracelltomi-google-tag-manager' ),
|
82 |
"description" => __( "Check this option to include the search term, referring page URL and number of results on the search page.", 'duracelltomi-google-tag-manager' ),
|
398 |
"phase" => GTM4WP_PHASE_STABLE,
|
399 |
"plugintocheck" => "contact-form-7/wp-contact-form-7.php"
|
400 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => array(
|
402 |
"label" => __( "Track classic e-commerce", 'duracelltomi-google-tag-manager' ),
|
403 |
"description" => __( sprintf( __( "Choose this option if you would like to track e-commerce data using <a href=\"%s\" target=\"_blank\">classic transaction data</a>.", 'duracelltomi-google-tag-manager' ) , 'https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce'), 'duracelltomi-google-tag-manager' ),
|
410 |
"phase" => GTM4WP_PHASE_BETA,
|
411 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
412 |
),
|
413 |
+
GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => array(
|
414 |
+
"label" => __( "Cart as 1st checkout step", 'duracelltomi-google-tag-manager' ),
|
415 |
+
"description" => __( "Enable this to track the cart page as the first checkout step in enhanced ecommerce instead of the checkout page itself", 'duracelltomi-google-tag-manager' ),
|
416 |
+
"phase" => GTM4WP_PHASE_BETA,
|
417 |
+
"plugintocheck" => "woocommerce/woocommerce.php"
|
418 |
+
),
|
419 |
GTM4WP_OPTION_INTEGRATE_WCREMARKETING => array(
|
420 |
"label" => __( "AdWords Remarketing", 'duracelltomi-google-tag-manager' ),
|
421 |
"description" => __( "Enable this to add Google AdWords dynamic remarketing variables to the dataLayer", 'duracelltomi-google-tag-manager' ),
|
422 |
"phase" => GTM4WP_PHASE_STABLE,
|
423 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
424 |
),
|
425 |
+
GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => array(
|
426 |
+
"label" => __( "Product ID prefix", 'duracelltomi-google-tag-manager' ),
|
427 |
+
"description" => __( "Some product feed generator plugins prefix product IDs with a fixed text like 'woocommerce_gpf'. You can enter this prefix here so that tags in your website include this prefix as well.", 'duracelltomi-google-tag-manager' ),
|
428 |
+
"phase" => GTM4WP_PHASE_BETA,
|
429 |
+
"plugintocheck" => "woocommerce/woocommerce.php"
|
430 |
+
),
|
431 |
GTM4WP_OPTION_INTEGRATE_WCUSESKU => array(
|
432 |
"label" => __( "Use SKU instead of ID", 'duracelltomi-google-tag-manager' ),
|
433 |
"description" => __( "Check this to use product SKU instead of the ID of the products for remarketing and ecommerce tracking. Will fallback to ID if no SKU is set.", 'duracelltomi-google-tag-manager' ),
|
434 |
+
"phase" => GTM4WP_PHASE_BETA,
|
435 |
"plugintocheck" => "woocommerce/woocommerce.php"
|
436 |
+
),
|
437 |
+
|
438 |
+
GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => array(
|
439 |
+
"label" => __( "Google Optimize page-hiding snippet ID list", 'duracelltomi-google-tag-manager' ),
|
440 |
+
"description" => sprintf( __( "Enter a comma separated list of Google Optimizie container IDs that you would like to use on your site using Google Tag Manager. This plugin will add the <a href=\"%s\">page-hiding snippet</a> to your pages.", 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/optimize/#the_page-hiding_snippet_code' ) .
|
441 |
+
'<br /><span class="goid_validation_error">' . __( "This does not seems to be a valid Google Optimize ID! Valid format: GTM-XXXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile IDs.", 'duracelltomi-google-tag-manager' ) . '</span>',
|
442 |
+
"phase" => GTM4WP_PHASE_EXPERIMENTAL
|
443 |
+
),
|
444 |
+
GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT => array(
|
445 |
+
"label" => __( "Google Optimize page-hiding timeout", 'duracelltomi-google-tag-manager' ),
|
446 |
+
"description" => __( "Enter here the amount of time in milliseconds that the page-hiding snippet should wait before page content gets visible even if Google Optimize has not been completely loaded yet.", 'duracelltomi-google-tag-manager' ),
|
447 |
+
"phase" => GTM4WP_PHASE_EXPERIMENTAL
|
448 |
)
|
449 |
);
|
450 |
|
455 |
case GTM4WP_ADMIN_GROUP_GENERAL: {
|
456 |
_e( 'This plugin is intended to be used by IT girls&guys and marketing staff. Please be sure you read the <a href="https://developers.google.com/tag-manager/" target="_blank">Google Tag Manager Help Center</a> before you start using this plugin.<br /><br />', 'duracelltomi-google-tag-manager' );
|
457 |
|
458 |
+
break;
|
459 |
}
|
460 |
|
461 |
case GTM4WP_ADMIN_GROUP_INCLUDES: {
|
467 |
_e( 'You are using an <strong>outdated</strong> version of PHP (5.3 or less). You <strong>should not turn on</strong> browser/device/os tracking as this can hurt your site. Please talk to your hosting and upgrade to PHP 5.4 or newer.', 'duracelltomi-google-tag-manager' );
|
468 |
}
|
469 |
|
470 |
+
break;
|
471 |
}
|
472 |
|
473 |
case GTM4WP_ADMIN_GROUP_EVENTS: {
|
476 |
_e( 'In October 2013 Google released a new feature called <a href="https://support.google.com/tagmanager/answer/3415369?hl=en" target="_blank">auto event tracking</a>. It is up to you how you use click events either using Google\'s solution or the settings below.', 'duracelltomi-google-tag-manager' );
|
477 |
echo '</p>';
|
478 |
|
479 |
+
break;
|
480 |
}
|
481 |
|
482 |
case GTM4WP_ADMIN_GROUP_SCROLLER: {
|
484 |
echo '<br />';
|
485 |
printf( __( 'Based on the script originaly posted to <a href="%s">Analytics Talk</a>', 'duracelltomi-google-tag-manager' ) , "http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/");
|
486 |
|
487 |
+
break;
|
488 |
}
|
489 |
|
490 |
case GTM4WP_ADMIN_GROUP_BLACKLIST: {
|
496 |
echo '<br />';
|
497 |
_e( "Uncheck a row to blacklist a macro type.", 'duracelltomi-google-tag-manager' );
|
498 |
|
499 |
+
break;
|
500 |
}
|
501 |
|
502 |
case GTM4WP_ADMIN_GROUP_INTEGRATION: {
|
503 |
_e( "Google Tag Manager for WordPress can integrate with several popular plugins. Please check the plugins you would like to integrate with:", 'duracelltomi-google-tag-manager' );
|
504 |
|
505 |
+
break;
|
506 |
}
|
507 |
|
508 |
case GTM4WP_ADMIN_GROUP_ADVANCED: {
|
509 |
_e( "You usually do not need to modify thoose settings. Please be carefull while hacking here.", 'duracelltomi-google-tag-manager' );
|
510 |
|
511 |
+
break;
|
512 |
}
|
513 |
|
514 |
case GTM4WP_ADMIN_GROUP_CREDITS: {
|
515 |
_e( "Some info about the author of this plugin", 'duracelltomi-google-tag-manager' );
|
516 |
|
517 |
+
break;
|
518 |
}
|
519 |
} // end switch
|
520 |
+
|
521 |
echo '</span>';
|
522 |
}
|
523 |
|
528 |
case GTM4WP_ADMIN_GROUP_GTMID: {
|
529 |
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"];
|
530 |
echo '<br /><span class="gtmid_validation_error">' . __( "This does not seems to be a valid Google Tag Manager ID! Valid format: GTM-XXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile container IDs.", 'duracelltomi-google-tag-manager' ) . '</span>';
|
531 |
+
|
532 |
break;
|
533 |
}
|
534 |
|
540 |
|
541 |
break;
|
542 |
}
|
543 |
+
|
544 |
case GTM4WP_ADMIN_GROUP_DATALAYER: {
|
545 |
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"];
|
546 |
echo '<br /><span class="datalayername_validation_error">' . __( "This does not seems to be a valid JavaScript variable name! Please check and try again", 'duracelltomi-google-tag-manager' ) . '</span>';
|
547 |
|
548 |
break;
|
549 |
}
|
550 |
+
|
551 |
case GTM4WP_OPTIONS . "[" . GTM4WP_OPTION_BLACKLIST_ENABLE . "]": {
|
552 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="0" ' . ( $gtm4wp_options[GTM4WP_OPTION_BLACKLIST_ENABLE] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( "Disable feature: control everything on Google Tag Manager interface", 'duracelltomi-google-tag-manager' ) . '<br />';
|
553 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="1" ' . ( $gtm4wp_options[GTM4WP_OPTION_BLACKLIST_ENABLE] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( "Allow all, except the checked items below (blacklist)", 'duracelltomi-google-tag-manager' ) . '<br />';
|
556 |
|
557 |
break;
|
558 |
}
|
559 |
+
|
560 |
case GTM4WP_OPTIONS . "[" . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . "]": {
|
561 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']" value="0" ' . ( $gtm4wp_options[GTM4WP_OPTION_INCLUDE_WEATHERUNITS] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( "Celsius", 'duracelltomi-google-tag-manager' ) . '<br />';
|
562 |
echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']" value="1" ' . ( $gtm4wp_options[GTM4WP_OPTION_INCLUDE_WEATHERUNITS] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( "Fahrenheit", 'duracelltomi-google-tag-manager' ) . '<br />';
|
618 |
|
619 |
function gtm4wp_sanitize_options($options) {
|
620 |
global $wpdb;
|
621 |
+
|
622 |
$output = gtm4wp_reload_options();
|
623 |
|
624 |
foreach($output as $optionname => $optionvalue) {
|
651 |
}
|
652 |
}
|
653 |
|
654 |
+
// Google Optimize settings
|
655 |
+
} else if ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ) {
|
656 |
+
$_goid_val = trim($newoptionvalue);
|
657 |
+
if ( "" == $_goid_val ) {
|
658 |
+
$_goid_list = array();
|
659 |
+
} else {
|
660 |
+
$_goid_list = explode( ",", $_goid_val );
|
661 |
+
}
|
662 |
+
$_goid_haserror = false;
|
663 |
+
|
664 |
+
foreach( $_goid_list as $one_go_id ) {
|
665 |
+
$_goid_haserror = $_goid_haserror || !preg_match( "/^GTM-[A-Z0-9]+$/", $one_go_id );
|
666 |
+
}
|
667 |
+
|
668 |
+
if ( $_goid_haserror && (count($_goid_list) > 0) ) {
|
669 |
+
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS . ']', __( "Invalid Google Optimize ID. Valid ID format: GTM-XXXXX. Use comma without additional space (,) to enter more than one ID.", 'duracelltomi-google-tag-manager' ) );
|
670 |
+
} else {
|
671 |
+
$output[$optionname] = $newoptionvalue;
|
672 |
+
}
|
673 |
+
|
674 |
+
} else if ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ) {
|
675 |
+
$output[$optionname] = (int) $newoptionvalue;
|
676 |
+
|
677 |
+
} else if ( $optionname == GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX ) {
|
678 |
+
$output[$optionname] = trim( (string) $newoptionvalue );
|
679 |
+
|
680 |
// integrations
|
681 |
} else if ( substr($optionname, 0, 10) == "integrate-" ) {
|
682 |
$output[$optionname] = (boolean) $newoptionvalue;
|
684 |
// GTM code or dataLayer variable name
|
685 |
} else if ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) ) {
|
686 |
$newoptionvalue = trim($newoptionvalue);
|
687 |
+
|
|
|
|
|
688 |
if ( $optionname == GTM4WP_OPTION_GTM_CODE ) {
|
689 |
$_gtmid_list = explode( ",", $newoptionvalue );
|
690 |
$_gtmid_haserror = false;
|
715 |
// scroll tracking content ID
|
716 |
} else if ( $optionname == GTM4WP_OPTION_SCROLLER_CONTENTID ) {
|
717 |
$output[$optionname] = trim( str_replace( "#", "", $newoptionvalue ) );
|
718 |
+
|
719 |
// anything else
|
720 |
} else {
|
721 |
switch( gettype($optionvalue)) {
|
737 |
} // end switch
|
738 |
}
|
739 |
}
|
740 |
+
|
741 |
return $output;
|
742 |
}
|
743 |
|
744 |
function gtm4wp_admin_init() {
|
745 |
global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts,
|
746 |
$gtm4wp_blacklistfieldtexts, $gtm4wp_blacklistmfieldtexts;
|
747 |
+
|
748 |
register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, "gtm4wp_sanitize_options" );
|
749 |
+
|
750 |
add_settings_section(
|
751 |
GTM4WP_ADMIN_GROUP_GENERAL,
|
752 |
__( 'General', 'duracelltomi-google-tag-manager' ),
|
753 |
'gtm4wp_admin_output_section',
|
754 |
GTM4WP_ADMINSLUG
|
755 |
);
|
756 |
+
|
757 |
add_settings_field(
|
758 |
GTM4WP_ADMIN_GROUP_GTMID,
|
759 |
__( 'Google Tag Manager ID', 'duracelltomi-google-tag-manager' ),
|
784 |
'gtm4wp_admin_output_section',
|
785 |
GTM4WP_ADMINSLUG
|
786 |
);
|
787 |
+
|
788 |
foreach($gtm4wp_includefieldtexts as $fieldid => $fielddata) {
|
789 |
add_settings_field(
|
790 |
"gtm4wp-admin-" . $fieldid . "-id",
|
806 |
'gtm4wp_admin_output_section',
|
807 |
GTM4WP_ADMINSLUG
|
808 |
);
|
809 |
+
|
810 |
foreach($gtm4wp_eventfieldtexts as $fieldid => $fielddata) {
|
811 |
add_settings_field(
|
812 |
"gtm4wp-admin-" . $fieldid . "-id",
|
828 |
'gtm4wp_admin_output_section',
|
829 |
GTM4WP_ADMINSLUG
|
830 |
);
|
831 |
+
|
832 |
foreach($gtm4wp_scrollerfieldtexts as $fieldid => $fielddata) {
|
833 |
add_settings_field(
|
834 |
"gtm4wp-admin-" . $fieldid . "-id",
|
850 |
'gtm4wp_admin_output_section',
|
851 |
GTM4WP_ADMINSLUG
|
852 |
);
|
853 |
+
|
854 |
foreach($gtm4wp_blacklistfieldtexts as $fieldid => $fielddata) {
|
855 |
add_settings_field(
|
856 |
"gtm4wp-admin-" . $fieldid . "-id",
|
899 |
"label_for" => "gtm4wp-options[" . $fieldid . "]",
|
900 |
"description" => $fielddata["description"],
|
901 |
"optionfieldid" => $fieldid,
|
902 |
+
"plugintocheck" => isset( $fielddata["plugintocheck"] ) ? $fielddata["plugintocheck"] : ""
|
903 |
)
|
904 |
);
|
905 |
}
|
994 |
"blockmacrostabtitle" => __( "Blacklist macros" , 'duracelltomi-google-tag-manager' ),
|
995 |
"wpcf7tabtitle" => __( "Contact Form 7" , 'duracelltomi-google-tag-manager' ),
|
996 |
"wctabtitle" => __( "WooCommerce" , 'duracelltomi-google-tag-manager' ),
|
997 |
+
"gotabtitle" => __( "Google Optimize" , 'duracelltomi-google-tag-manager' ),
|
998 |
"weathertabtitle" => __( "Weather data" , 'duracelltomi-google-tag-manager' ),
|
999 |
"generaleventstabtitle" => __( "General events" , 'duracelltomi-google-tag-manager' ),
|
1000 |
"mediaeventstabtitle" => __( "Media events" , 'duracelltomi-google-tag-manager' ),
|
1014 |
echo '
|
1015 |
<style type="text/css">
|
1016 |
.gtmid_validation_error,
|
1017 |
+
.goid_validation_error,
|
1018 |
.datalayername_validation_error {
|
1019 |
display: none;
|
1020 |
color: #c00;
|
1026 |
jQuery( "#gtm4wp-options\\\\[gtm-code\\\\]" )
|
1027 |
.bind( "blur", function() {
|
1028 |
var gtmid_regex = /^GTM-[A-Z0-9]+$/;
|
1029 |
+
var gtmid_list = jQuery( this ).val().trim().split( "," );
|
1030 |
|
1031 |
var gtmid_haserror = false;
|
1032 |
for( var i=0; i<gtmid_list.length; i++ ) {
|
1042 |
}
|
1043 |
});
|
1044 |
|
1045 |
+
jQuery( "#gtm4wp-options\\\\[integrate-google-optimize-idlist\\\\]" )
|
1046 |
+
.bind( "blur", function() {
|
1047 |
+
var goid_regex = /^GTM-[A-Z0-9]+$/;
|
1048 |
+
var goid_val = jQuery( this ).val().trim();
|
1049 |
+
if ( "" == goid_val ) {
|
1050 |
+
goid_list = [];
|
1051 |
+
} else {
|
1052 |
+
var goid_list = goid_val.split( "," );
|
1053 |
+
}
|
1054 |
+
|
1055 |
+
var goid_haserror = false;
|
1056 |
+
for( var i=0; i<goid_list.length; i++ ) {
|
1057 |
+
goid_haserror = goid_haserror || !goid_regex.test( goid_list[ i ] );
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
if ( goid_haserror && (goid_list.length > 0) ) {
|
1061 |
+
jQuery( ".goid_validation_error" )
|
1062 |
+
.show();
|
1063 |
+
} else {
|
1064 |
+
jQuery( ".goid_validation_error" )
|
1065 |
+
.hide();
|
1066 |
+
}
|
1067 |
+
});
|
1068 |
+
|
1069 |
jQuery( "#gtm4wp-options\\\\[gtm-datalayer-variable-name\\\\]" )
|
1070 |
.bind( "blur", function() {
|
1071 |
var currentval = jQuery( this ).val();
|
1083 |
}
|
1084 |
});
|
1085 |
|
1086 |
+
jQuery( document )
|
1087 |
+
.on( "click", ".gtm4wp-notice .notice-dismiss", function( e ) {
|
|
|
|
|
1088 |
jQuery.post(ajaxurl, {
|
1089 |
action: "gtm4wp_dismiss_notice",
|
1090 |
+
noticeid: jQuery( this ).closest(".gtm4wp-notice")
|
1091 |
+
.attr( "data-href" )
|
1092 |
.substring( 1 )
|
|
|
|
|
|
|
|
|
|
|
1093 |
});
|
1094 |
});
|
1095 |
});
|
1112 |
$gtm4wp_user_notices_dismisses = array_merge( $gtm4wp_def_user_notices_dismisses, $gtm4wp_user_notices_dismisses );
|
1113 |
|
1114 |
if ( ( trim( $gtm4wp_options[GTM4WP_OPTION_GTM_CODE] ) == "" ) && ( false === $gtm4wp_user_notices_dismisses["enter-gtm-code"] ) ) {
|
1115 |
+
echo '<div class="gtm4wp-notice notice notice-error is-dismissible" data-href="?enter-gtm-code"><p><strong>' . sprintf( __( 'To start using Google Tag Manager for WordPress, please <a href="%s">enter your GTM ID</a>', 'duracelltomi-google-tag-manager' ), "options-general.php?page=" . GTM4WP_ADMINSLUG ) . '</strong></p></div>';
|
1116 |
}
|
1117 |
|
1118 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-ga-plugin-warning"] ) || ( false === $gtm4wp_user_notices_dismisses["wc-gayoast-plugin-warning"] ) || ( false === $gtm4wp_user_notices_dismisses["wc-1-3-upgrade-info"] ) ) {
|
1124 |
$woo_ga_options = get_option( "woocommerce_google_analytics_settings" );
|
1125 |
if ( $woo_ga_options ) {
|
1126 |
if ( "" != $woo_ga_options["ga_id"] ) {
|
1127 |
+
echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-ga-plugin-warning"><p><strong>' . __( 'Notice: you should disable Google Analytics tracking <a href="admin.php?page=woocommerce_settings&tab=integration§ion=google_analytics">in WooCommerce settings</a> by leaving Google Analytics ID field empty if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
|
1128 |
}
|
1129 |
}
|
1130 |
}
|
1131 |
|
1132 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-ga-plugin-warning"] ) && $is_wc_active && is_plugin_active( "woocommerce-google-analytics-integration/woocommerce-google-analytics-integration.php" ) ) {
|
1133 |
+
echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-ga-plugin-warning"><p><strong>' . __( 'Notice: you should deactivate the plugin "WooCommerce Google Analytics Integration" if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
|
1134 |
}
|
1135 |
|
1136 |
if ( ( false === $gtm4wp_user_notices_dismisses["wc-gayoast-plugin-warning"] ) && $is_wc_active && is_plugin_active( "google-analytics-for-wordpress/googleanalytics.php" ) ) {
|
1137 |
+
echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-gayoast-plugin-warning"><p><strong>' . __( 'Notice: you should deactivate the plugin "Google Analytics for WordPress by MonsterInsights" if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
|
1138 |
}
|
1139 |
|
1140 |
if ( $is_wc_active && ( false === $gtm4wp_user_notices_dismisses["wc-1-3-upgrade-info"] ) ) {
|
1141 |
+
echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-1-3-upgrade-info"><p><strong>' . sprintf( __( 'Warning: Using WooCommerce and upgrading to v1.3 of the GTM plugin? <a href="%s" target="_blank">Check this important blog post.</a>', 'duracelltomi-google-tag-manager' ), "https://duracelltomi.com/google-tag-manager-for-wordpress/how-to-articles/upgrading-woocommerce-settings-for-v1-3" ) . '</strong></p></div>';
|
1142 |
}
|
1143 |
}
|
1144 |
}
|
common/readoptions.php
CHANGED
@@ -80,14 +80,19 @@ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT', 'blacklist-macro-autoevent-
|
|
80 |
|
81 |
define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
|
82 |
|
83 |
-
define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE',
|
84 |
-
define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC',
|
85 |
-
define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC',
|
86 |
-
define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING',
|
87 |
-
define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU',
|
|
|
|
|
|
|
|
|
88 |
|
89 |
define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
|
90 |
|
|
|
91 |
define( 'GTM4WP_PLACEMENT_FOOTER', 0 );
|
92 |
define( 'GTM4WP_PLACEMENT_BODYOPEN', 1 );
|
93 |
define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
|
@@ -177,10 +182,15 @@ $gtm4wp_defaultoptions = array(
|
|
177 |
GTM4WP_OPTION_INTEGRATE_WPCF7 => false,
|
178 |
|
179 |
// GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE => false,
|
180 |
-
GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC
|
181 |
-
GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC
|
182 |
-
GTM4WP_OPTION_INTEGRATE_WCREMARKETING
|
183 |
-
GTM4WP_OPTION_INTEGRATE_WCUSESKU
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false
|
186 |
);
|
80 |
|
81 |
define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
|
82 |
|
83 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE', 'integrate-woocommerce' );
|
84 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC', 'integrate-woocommerce-track-classic-ecommerce' );
|
85 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC', 'integrate-woocommerce-track-enhanced-ecommerce' );
|
86 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING', 'integrate-woocommerce-remarketing' );
|
87 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU', 'integrate-woocommerce-remarketing-usesku' );
|
88 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX', 'integrate-woocommerce-remarketing-productidprefix' );
|
89 |
+
define( 'GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP', 'integrate-woocommerce-cart-as-first-step' );
|
90 |
+
define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS', 'integrate-google-optimize-idlist' );
|
91 |
+
define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT', 'integrate-google-optimize-timeout' );
|
92 |
|
93 |
define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
|
94 |
|
95 |
+
|
96 |
define( 'GTM4WP_PLACEMENT_FOOTER', 0 );
|
97 |
define( 'GTM4WP_PLACEMENT_BODYOPEN', 1 );
|
98 |
define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
|
182 |
GTM4WP_OPTION_INTEGRATE_WPCF7 => false,
|
183 |
|
184 |
// GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE => false,
|
185 |
+
GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => false,
|
186 |
+
GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => false,
|
187 |
+
GTM4WP_OPTION_INTEGRATE_WCREMARKETING => false,
|
188 |
+
GTM4WP_OPTION_INTEGRATE_WCUSESKU => false,
|
189 |
+
GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => "",
|
190 |
+
GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => false,
|
191 |
+
|
192 |
+
GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => "",
|
193 |
+
GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT => 4000,
|
194 |
|
195 |
GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false
|
196 |
);
|
duracelltomi-google-tag-manager-for-wordpress.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Google Tag Manager for Wordpress
|
4 |
-
Version: 1.
|
5 |
Plugin URI: https://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
|
@@ -10,7 +10,7 @@ Text Domain: duracelltomi-google-tag-manager
|
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
-
define( 'GTM4WP_VERSION', '1.
|
14 |
define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
|
15 |
|
16 |
$gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Google Tag Manager for Wordpress
|
4 |
+
Version: 1.7
|
5 |
Plugin URI: https://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
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
+
define( 'GTM4WP_VERSION', '1.7' );
|
14 |
define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
|
15 |
|
16 |
$gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
|
integration/google-optimize.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
function gtm4wp_go_pagehiding_snippet() {
|
3 |
+
global $gtm4wp_options;
|
4 |
+
|
5 |
+
$gtm4wp_goids = explode( ",", $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] );
|
6 |
+
$gtm4wp_goid_list = array();
|
7 |
+
if ( count( $gtm4wp_goids ) > 0 ) {
|
8 |
+
foreach( $gtm4wp_goids as $gtm4wp_onegoid ) {
|
9 |
+
$gtm4wp_goid_list[] = "'" . $gtm4wp_onegoid . "': true";
|
10 |
+
}
|
11 |
+
|
12 |
+
$gtm4wp_gotimeout = (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ];
|
13 |
+
if ( 0 == $gtm4wp_gotimeout ) {
|
14 |
+
$gtm4wp_gotimeout = 4000;
|
15 |
+
}
|
16 |
+
|
17 |
+
echo "<style>.google-optimize-hide { opacity: 0 !important} </style>
|
18 |
+
<script>
|
19 |
+
(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
|
20 |
+
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
|
21 |
+
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
|
22 |
+
})
|
23 |
+
(window,document.documentElement,'google-optimize-hide','dataLayer'," . $gtm4wp_gotimeout . ",{" . implode( ", ", $gtm4wp_goid_list ) . "});
|
24 |
+
</script>";
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
add_action( "wp_head", "gtm4wp_go_pagehiding_snippet", 1 );
|
integration/woocommerce.php
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
<?php
|
2 |
define( 'GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY', 'gtm4wp_eec_product_array' );
|
3 |
|
4 |
-
$gtm4wp_product_counter
|
5 |
$gtm4wp_last_widget_title = "Sidebar Products";
|
|
|
6 |
|
7 |
function gtm4wp_woocommerce_addjs( $js ) {
|
8 |
global $woocommerce;
|
@@ -18,8 +19,18 @@ function gtm4wp_woocommerce_html_entity_decode( $val ) {
|
|
18 |
return html_entity_decode( $val, ENT_QUOTES, "utf-8" );
|
19 |
}
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
22 |
-
global $woocommerce, $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter;
|
23 |
|
24 |
if ( is_product_category() || is_product_tag() || is_front_page() || is_shop() ) {
|
25 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
@@ -33,7 +44,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
33 |
$product = wc_get_product( $postid );
|
34 |
$product_id = $product->get_id();
|
35 |
|
36 |
-
$_product_cats = get_the_terms( $
|
37 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
38 |
$product_cat = array_pop( $_product_cats );
|
39 |
$product_cat = $product_cat->name;
|
@@ -41,7 +52,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
41 |
$product_cat = "";
|
42 |
}
|
43 |
|
44 |
-
if ( "variable" != $product->
|
45 |
$product_price = $product->get_price();
|
46 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
|
47 |
$product_sku = $product->get_sku();
|
@@ -61,7 +72,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
61 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
62 |
$remarketing_id = (string)$product_id;
|
63 |
|
64 |
-
$dataLayer["ecomm_prodid"] = $remarketing_id;
|
65 |
$dataLayer["ecomm_pagetype"] = "product";
|
66 |
$dataLayer["ecomm_totalvalue"] = (float)$eec_product_array[ "price" ];
|
67 |
}
|
@@ -79,17 +90,21 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
79 |
$dataLayer["ecomm_totalvalue"] = 0;
|
80 |
|
81 |
gtm4wp_woocommerce_addjs("
|
|
|
82 |
var gtm4wp_product_detail_data = {
|
83 |
name: '" . gtm4wp_woocommerce_html_entity_decode( get_the_title() ) . "',
|
84 |
id: 0,
|
85 |
price: 0,
|
86 |
-
category: '" . $product_cat . "',
|
87 |
variant: ''
|
88 |
};
|
89 |
|
90 |
jQuery(document).on( 'found_variation', function( event, product_variation ) {
|
91 |
var current_product_detail_data = gtm4wp_product_detail_data;
|
92 |
current_product_detail_data.id = product_variation.variation_id;
|
|
|
|
|
|
|
93 |
current_product_detail_data.price = product_variation.display_price;
|
94 |
|
95 |
var _tmp = [];
|
@@ -102,11 +117,13 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
102 |
'event': 'gtm4wp.changeDetailViewEEC',
|
103 |
'ecommerce': {
|
104 |
'currencyCode': '".get_woocommerce_currency()."',
|
105 |
-
'detail':
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
});
|
111 |
});
|
112 |
|
@@ -170,27 +187,70 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
170 |
");
|
171 |
}
|
172 |
|
173 |
-
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
174 |
-
$
|
175 |
-
$
|
176 |
-
|
177 |
-
|
178 |
-
$
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
$remarketing_id = $product_sku;
|
181 |
}
|
182 |
|
183 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
|
186 |
-
$
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
}
|
193 |
-
$dataLayer["ecomm_totalvalue"] = (float)$cart_total;
|
194 |
}
|
195 |
} else if ( is_order_received_page() ) {
|
196 |
$order_id = empty( $_GET[ "order" ] ) ? ( $GLOBALS[ "wp" ]->query_vars[ "order-received" ] ? $GLOBALS[ "wp" ]->query_vars[ "order-received" ] : 0 ) : absint( $_GET[ "order" ] );
|
@@ -203,7 +263,13 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
203 |
|
204 |
if ( $order_id > 0 ) {
|
205 |
$order = new WC_Order( $order_id );
|
206 |
-
if ( $
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
unset( $order );
|
208 |
}
|
209 |
|
@@ -218,9 +284,13 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
218 |
$dataLayer["transactionType"] = "sale";
|
219 |
$dataLayer["transactionAffiliation"] = gtm4wp_woocommerce_html_entity_decode( get_bloginfo( 'name' ) );
|
220 |
$dataLayer["transactionTotal"] = $order->get_total();
|
221 |
-
$
|
|
|
|
|
|
|
|
|
222 |
$dataLayer["transactionTax"] = $order->get_total_tax();
|
223 |
-
$dataLayer["transactionPaymentType"] = $order->
|
224 |
$dataLayer["transactionCurrency"] = get_woocommerce_currency();
|
225 |
$dataLayer["transactionShippingMethod"] = $order->get_shipping_method();
|
226 |
$dataLayer["transactionPromoCode"] = implode( ", ", $order->get_used_coupons() );
|
@@ -235,7 +305,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
235 |
"affiliation" => gtm4wp_woocommerce_html_entity_decode( get_bloginfo( 'name' ) ),
|
236 |
"revenue" => $order->get_total(),
|
237 |
"tax" => $order->get_total_tax(),
|
238 |
-
"shipping" => $order->get_total_shipping(),
|
239 |
"coupon" => implode( ", ", $order->get_used_coupons() )
|
240 |
)
|
241 |
)
|
@@ -248,14 +318,14 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
248 |
|
249 |
if ( $order->get_items() ) {
|
250 |
foreach ( $order->get_items() as $item ) {
|
251 |
-
if (
|
252 |
$product = $item->get_product();
|
253 |
} else {
|
254 |
$product = $order->get_product_from_item( $item );
|
255 |
}
|
256 |
|
257 |
$product_id = $product->get_id();
|
258 |
-
$_product_cats = get_the_terms($
|
259 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
260 |
$product_cat = array_pop( $_product_cats );
|
261 |
$product_cat = $product_cat->name;
|
@@ -288,7 +358,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
288 |
$_products[] = $eec_product_array;
|
289 |
|
290 |
$_sumprice += $product_price * $eec_product_array[ "quantity" ];
|
291 |
-
$_product_ids[] = $remarketing_id;
|
292 |
}
|
293 |
}
|
294 |
|
@@ -321,7 +391,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
321 |
|
322 |
$product_id = $product->get_id();
|
323 |
|
324 |
-
$_product_cats = get_the_terms($
|
325 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
326 |
$product_cat = array_pop( $_product_cats );
|
327 |
$product_cat = $product_cat->name;
|
@@ -337,7 +407,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
337 |
|
338 |
$_temp_productdata = array(
|
339 |
"id" => $remarketing_id,
|
340 |
-
"name" => $product->
|
341 |
"price" => $product->get_price(),
|
342 |
"category" => $product_cat,
|
343 |
"quantity" => $cart_item_data["quantity"]
|
@@ -350,7 +420,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
350 |
$eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "checkout" );
|
351 |
$gtm4wp_checkout_products[] = $eec_product_array;
|
352 |
|
353 |
-
$gtm4wp_checkout_products_remarketing[] = $remarketing_id;
|
354 |
$gtm4wp_totalvalue += $eec_product_array[ "quantity" ] * $eec_product_array[ "price" ];
|
355 |
} // end foreach cart item
|
356 |
|
@@ -364,7 +434,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
364 |
$dataLayer["ecommerce"] = array(
|
365 |
"checkout" => array(
|
366 |
"actionField" => array(
|
367 |
-
"step" => 1
|
368 |
),
|
369 |
"products" => $gtm4wp_checkout_products
|
370 |
)
|
@@ -449,6 +519,43 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
|
449 |
");
|
450 |
}
|
451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
return $dataLayer;
|
453 |
}
|
454 |
|
@@ -464,7 +571,9 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
|
|
464 |
return;
|
465 |
}
|
466 |
|
467 |
-
$
|
|
|
|
|
468 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
469 |
$product_cat = array_pop( $_product_cats );
|
470 |
$product_cat = $product_cat->name;
|
@@ -472,7 +581,6 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
|
|
472 |
$product_cat = "";
|
473 |
}
|
474 |
|
475 |
-
$product_id = $product->get_id();
|
476 |
$remarketing_id = $product_id;
|
477 |
$product_sku = $product->get_sku();
|
478 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
|
@@ -481,7 +589,7 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
|
|
481 |
|
482 |
$_temp_productdata = array(
|
483 |
"id" => $remarketing_id,
|
484 |
-
"name" => $product->
|
485 |
"sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $product_id,
|
486 |
"category" => $product_cat,
|
487 |
"price" => $product->get_price(),
|
@@ -609,7 +717,7 @@ function gtm4wp_woocommerce_wp_footer() {
|
|
609 |
$( '.gtm4wp_productdata' ).each( function() {
|
610 |
productdata = jQuery( this );
|
611 |
|
612 |
-
". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push( productdata.data( 'gtm4wp_product_id' ) );
|
613 |
});
|
614 |
}
|
615 |
})(jQuery);
|
@@ -757,7 +865,7 @@ function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
|
|
757 |
global $product, $woocommerce_loop, $wp_query, $gtm4wp_options;
|
758 |
|
759 |
$product_id = $product->get_id();
|
760 |
-
$_product_cats = get_the_terms($
|
761 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
762 |
$product_cat = array_pop( $_product_cats );
|
763 |
$product_cat = $product_cat->name;
|
@@ -787,7 +895,7 @@ function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
|
|
787 |
|
788 |
$_temp_productdata = array(
|
789 |
"id" => $remarketing_id,
|
790 |
-
"name" => $product->
|
791 |
"category" => $product_cat,
|
792 |
"price" => $product->get_price(),
|
793 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
@@ -795,7 +903,7 @@ function gtm4wp_woocommerce_add_prod_data( $add_to_cart_link ) {
|
|
795 |
"listname" => $list_name
|
796 |
);
|
797 |
|
798 |
-
if ( "variation" == $product->
|
799 |
$_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
|
800 |
} else {
|
801 |
$_temp_productdata[ "variant" ] = "";
|
@@ -822,7 +930,7 @@ function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $
|
|
822 |
global $gtm4wp_options;
|
823 |
|
824 |
$product_id = $product->get_id();
|
825 |
-
$_product_cats = get_the_terms($
|
826 |
if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
|
827 |
$product_cat = array_pop( $_product_cats );
|
828 |
$product_cat = $product_cat->name;
|
@@ -838,13 +946,13 @@ function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $
|
|
838 |
|
839 |
$_temp_productdata = array(
|
840 |
"id" => $remarketing_id,
|
841 |
-
"name" => $product->
|
842 |
"price" => $product->get_price(),
|
843 |
"category" => $product_cat,
|
844 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0)
|
845 |
);
|
846 |
|
847 |
-
if ( "variation" == $product->
|
848 |
$_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
|
849 |
} else {
|
850 |
$_temp_productdata[ "variant" ] = "";
|
@@ -904,7 +1012,7 @@ function gtm4wp_woocommerce_after_template_part( $template_name ) {
|
|
904 |
|
905 |
if ( "content-widget-product.php" == $template_name ) {
|
906 |
$product_id = $product->get_id();
|
907 |
-
$_product_cats = get_the_terms($
|
908 |
if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
|
909 |
$product_cat = array_pop( $_product_cats );
|
910 |
$product_cat = $product_cat->name;
|
@@ -920,7 +1028,7 @@ function gtm4wp_woocommerce_after_template_part( $template_name ) {
|
|
920 |
|
921 |
$_temp_productdata = array(
|
922 |
"id" => $remarketing_id,
|
923 |
-
"name" => $product->
|
924 |
"price" => $product->get_price(),
|
925 |
"category" => $product_cat,
|
926 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
@@ -1006,7 +1114,7 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
|
|
1006 |
$cat_obj = $wp_query->get_queried_object();
|
1007 |
$product_cat = $cat_obj->name;
|
1008 |
} else {
|
1009 |
-
$_product_cats = get_the_terms($
|
1010 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
1011 |
$last_product_cat = array_pop( $_product_cats );
|
1012 |
$product_cat = $last_product_cat->name;
|
@@ -1035,7 +1143,7 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
|
|
1035 |
|
1036 |
$_temp_productdata = array(
|
1037 |
"id" => $remarketing_id,
|
1038 |
-
"name" => $product->
|
1039 |
"price" => $product->get_price(),
|
1040 |
"category" => $product_cat,
|
1041 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
@@ -1055,6 +1163,12 @@ function gtm4wp_woocommerce_before_shop_loop_item() {
|
|
1055 |
);
|
1056 |
}
|
1057 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1058 |
// do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
|
1059 |
if ( isset ( $GLOBALS["woocommerce"] ) ) {
|
1060 |
add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_items" );
|
@@ -1084,5 +1198,6 @@ if ( isset ( $GLOBALS["woocommerce"] ) ) {
|
|
1084 |
add_action( 'woocommerce_shortcode_before_top_rated_products_loop', 'gtm4wp_before_top_rated_products_loop' );
|
1085 |
add_action( 'woocommerce_shortcode_before_featured_products_loop', 'gtm4wp_before_featured_products_loop' );
|
1086 |
add_action( 'woocommerce_shortcode_before_related_products_loop', 'gtm4wp_before_related_products_loop' );
|
|
|
1087 |
}
|
1088 |
}
|
1 |
<?php
|
2 |
define( 'GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY', 'gtm4wp_eec_product_array' );
|
3 |
|
4 |
+
$gtm4wp_product_counter = 0;
|
5 |
$gtm4wp_last_widget_title = "Sidebar Products";
|
6 |
+
$gtm4wp_is_woocommerce3 = version_compare( $GLOBALS["woocommerce"]->version, "3.0", ">=" );
|
7 |
|
8 |
function gtm4wp_woocommerce_addjs( $js ) {
|
9 |
global $woocommerce;
|
19 |
return html_entity_decode( $val, ENT_QUOTES, "utf-8" );
|
20 |
}
|
21 |
|
22 |
+
function gtm4wp_prefix_productid( $product_id ) {
|
23 |
+
global $gtm4wp_options;
|
24 |
+
|
25 |
+
if ( "" != $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX ] ) {
|
26 |
+
return $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX ] . $product_id;
|
27 |
+
} else {
|
28 |
+
return $product_id;
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
|
33 |
+
global $woocommerce, $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3;
|
34 |
|
35 |
if ( is_product_category() || is_product_tag() || is_front_page() || is_shop() ) {
|
36 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
44 |
$product = wc_get_product( $postid );
|
45 |
$product_id = $product->get_id();
|
46 |
|
47 |
+
$_product_cats = get_the_terms( $product_id, 'product_cat' );
|
48 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
49 |
$product_cat = array_pop( $_product_cats );
|
50 |
$product_cat = $product_cat->name;
|
52 |
$product_cat = "";
|
53 |
}
|
54 |
|
55 |
+
if ( "variable" != $product->get_type() ) {
|
56 |
$product_price = $product->get_price();
|
57 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] ) {
|
58 |
$product_sku = $product->get_sku();
|
72 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
73 |
$remarketing_id = (string)$product_id;
|
74 |
|
75 |
+
$dataLayer["ecomm_prodid"] = gtm4wp_prefix_productid( $remarketing_id );
|
76 |
$dataLayer["ecomm_pagetype"] = "product";
|
77 |
$dataLayer["ecomm_totalvalue"] = (float)$eec_product_array[ "price" ];
|
78 |
}
|
90 |
$dataLayer["ecomm_totalvalue"] = 0;
|
91 |
|
92 |
gtm4wp_woocommerce_addjs("
|
93 |
+
var gtm4wp_use_sku_instead = " . (int)($gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ]) . ";
|
94 |
var gtm4wp_product_detail_data = {
|
95 |
name: '" . gtm4wp_woocommerce_html_entity_decode( get_the_title() ) . "',
|
96 |
id: 0,
|
97 |
price: 0,
|
98 |
+
category: '" . esc_js( $product_cat ) . "',
|
99 |
variant: ''
|
100 |
};
|
101 |
|
102 |
jQuery(document).on( 'found_variation', function( event, product_variation ) {
|
103 |
var current_product_detail_data = gtm4wp_product_detail_data;
|
104 |
current_product_detail_data.id = product_variation.variation_id;
|
105 |
+
if ( gtm4wp_use_sku_instead && product_variation.sku && ('' != product_variation.sku) ) {
|
106 |
+
current_product_detail_data.id = product_variation.sku;
|
107 |
+
}
|
108 |
current_product_detail_data.price = product_variation.display_price;
|
109 |
|
110 |
var _tmp = [];
|
117 |
'event': 'gtm4wp.changeDetailViewEEC',
|
118 |
'ecommerce': {
|
119 |
'currencyCode': '".get_woocommerce_currency()."',
|
120 |
+
'detail': {
|
121 |
+
'products': [current_product_detail_data]
|
122 |
+
},
|
123 |
+
},
|
124 |
+
'ecomm_prodid': '".gtm4wp_prefix_productid("")."' + current_product_detail_data.id,
|
125 |
+
'ecomm_pagetype': 'product',
|
126 |
+
'ecomm_totalvalue': 0
|
127 |
});
|
128 |
});
|
129 |
|
187 |
");
|
188 |
}
|
189 |
|
190 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
|
191 |
+
$gtm4wp_cart_products = array();
|
192 |
+
$gtm4wp_cart_products_remarketing = array();
|
193 |
+
|
194 |
+
foreach( $woocommerce->cart->get_cart() as $cart_item_id => $cart_item_data) {
|
195 |
+
$product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data["data"], $cart_item_data, $cart_item_id );
|
196 |
+
|
197 |
+
$product_id = $product->get_id();
|
198 |
+
|
199 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
200 |
+
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
201 |
+
$product_cat = array_pop( $_product_cats );
|
202 |
+
$product_cat = $product_cat->name;
|
203 |
+
} else {
|
204 |
+
$product_cat = "";
|
205 |
+
}
|
206 |
+
|
207 |
+
$remarketing_id = $product_id;
|
208 |
+
$product_sku = $product->get_sku();
|
209 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
|
210 |
$remarketing_id = $product_sku;
|
211 |
}
|
212 |
|
213 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
|
214 |
+
$_temp_productdata = array(
|
215 |
+
"id" => $remarketing_id,
|
216 |
+
"name" => $product->get_title(),
|
217 |
+
"price" => $product->get_price(),
|
218 |
+
"category" => $product_cat,
|
219 |
+
"quantity" => $cart_item_data["quantity"]
|
220 |
+
);
|
221 |
+
|
222 |
+
if ( "variation" == $product->get_type() ) {
|
223 |
+
$_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
|
224 |
+
}
|
225 |
+
|
226 |
+
$eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" );
|
227 |
+
$gtm4wp_cart_products[] = $eec_product_array;
|
228 |
+
}
|
229 |
+
|
230 |
+
$gtm4wp_cart_products_remarketing[] = gtm4wp_prefix_productid( $remarketing_id );
|
231 |
}
|
232 |
|
233 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) {
|
234 |
+
$dataLayer["ecomm_prodid"] = $gtm4wp_cart_products_remarketing;
|
235 |
+
$dataLayer["ecomm_pagetype"] = "cart";
|
236 |
+
if ( ! $woocommerce->cart->prices_include_tax ) {
|
237 |
+
$cart_total = $woocommerce->cart->cart_contents_total;
|
238 |
+
} else {
|
239 |
+
$cart_total = $woocommerce->cart->cart_contents_total + $woocommerce->cart->tax_total;
|
240 |
+
}
|
241 |
+
$dataLayer["ecomm_totalvalue"] = (float)$cart_total;
|
242 |
+
}
|
243 |
+
|
244 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
|
245 |
+
$dataLayer["ecommerce"] = array(
|
246 |
+
"checkout" => array(
|
247 |
+
"actionField" => array(
|
248 |
+
"step" => 1
|
249 |
+
),
|
250 |
+
"products" => $gtm4wp_cart_products
|
251 |
+
)
|
252 |
+
);
|
253 |
}
|
|
|
254 |
}
|
255 |
} else if ( is_order_received_page() ) {
|
256 |
$order_id = empty( $_GET[ "order" ] ) ? ( $GLOBALS[ "wp" ]->query_vars[ "order-received" ] ? $GLOBALS[ "wp" ]->query_vars[ "order-received" ] : 0 ) : absint( $_GET[ "order" ] );
|
263 |
|
264 |
if ( $order_id > 0 ) {
|
265 |
$order = new WC_Order( $order_id );
|
266 |
+
if ( $gtm4wp_is_woocommerce3 ) {
|
267 |
+
$this_order_key = $order->get_order_key();
|
268 |
+
} else {
|
269 |
+
$this_order_key = $order->order_key;
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( $this_order_key != $order_key )
|
273 |
unset( $order );
|
274 |
}
|
275 |
|
284 |
$dataLayer["transactionType"] = "sale";
|
285 |
$dataLayer["transactionAffiliation"] = gtm4wp_woocommerce_html_entity_decode( get_bloginfo( 'name' ) );
|
286 |
$dataLayer["transactionTotal"] = $order->get_total();
|
287 |
+
if ( $gtm4wp_is_woocommerce3 ) {
|
288 |
+
$dataLayer["transactionShipping"] = $order->get_shipping_total();
|
289 |
+
} else {
|
290 |
+
$dataLayer["transactionShipping"] = $order->get_total_shipping();
|
291 |
+
}
|
292 |
$dataLayer["transactionTax"] = $order->get_total_tax();
|
293 |
+
$dataLayer["transactionPaymentType"] = $order->get_payment_method_title();
|
294 |
$dataLayer["transactionCurrency"] = get_woocommerce_currency();
|
295 |
$dataLayer["transactionShippingMethod"] = $order->get_shipping_method();
|
296 |
$dataLayer["transactionPromoCode"] = implode( ", ", $order->get_used_coupons() );
|
305 |
"affiliation" => gtm4wp_woocommerce_html_entity_decode( get_bloginfo( 'name' ) ),
|
306 |
"revenue" => $order->get_total(),
|
307 |
"tax" => $order->get_total_tax(),
|
308 |
+
"shipping" => ( $gtm4wp_is_woocommerce3 ? $order->get_shipping_total() : $order->get_total_shipping()),
|
309 |
"coupon" => implode( ", ", $order->get_used_coupons() )
|
310 |
)
|
311 |
)
|
318 |
|
319 |
if ( $order->get_items() ) {
|
320 |
foreach ( $order->get_items() as $item ) {
|
321 |
+
if ( $gtm4wp_is_woocommerce3 ) {
|
322 |
$product = $item->get_product();
|
323 |
} else {
|
324 |
$product = $order->get_product_from_item( $item );
|
325 |
}
|
326 |
|
327 |
$product_id = $product->get_id();
|
328 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
329 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
330 |
$product_cat = array_pop( $_product_cats );
|
331 |
$product_cat = $product_cat->name;
|
358 |
$_products[] = $eec_product_array;
|
359 |
|
360 |
$_sumprice += $product_price * $eec_product_array[ "quantity" ];
|
361 |
+
$_product_ids[] = gtm4wp_prefix_productid( $remarketing_id );
|
362 |
}
|
363 |
}
|
364 |
|
391 |
|
392 |
$product_id = $product->get_id();
|
393 |
|
394 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
395 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
396 |
$product_cat = array_pop( $_product_cats );
|
397 |
$product_cat = $product_cat->name;
|
407 |
|
408 |
$_temp_productdata = array(
|
409 |
"id" => $remarketing_id,
|
410 |
+
"name" => $product->get_title(),
|
411 |
"price" => $product->get_price(),
|
412 |
"category" => $product_cat,
|
413 |
"quantity" => $cart_item_data["quantity"]
|
420 |
$eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "checkout" );
|
421 |
$gtm4wp_checkout_products[] = $eec_product_array;
|
422 |
|
423 |
+
$gtm4wp_checkout_products_remarketing[] = gtm4wp_prefix_productid( $remarketing_id );
|
424 |
$gtm4wp_totalvalue += $eec_product_array[ "quantity" ] * $eec_product_array[ "price" ];
|
425 |
} // end foreach cart item
|
426 |
|
434 |
$dataLayer["ecommerce"] = array(
|
435 |
"checkout" => array(
|
436 |
"actionField" => array(
|
437 |
+
"step" => 1 + (int)$gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
|
438 |
),
|
439 |
"products" => $gtm4wp_checkout_products
|
440 |
)
|
519 |
");
|
520 |
}
|
521 |
|
522 |
+
if ( isset ( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] ) ) {
|
523 |
+
$cart_item = $woocommerce->cart->get_cart_item( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
|
524 |
+
if ( !empty( $cart_item ) ) {
|
525 |
+
$product = $cart_item["data"];
|
526 |
+
$product_id = $product->get_id();
|
527 |
+
|
528 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
529 |
+
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
530 |
+
$product_cat = array_pop( $_product_cats );
|
531 |
+
$product_cat = $product_cat->name;
|
532 |
+
} else {
|
533 |
+
$product_cat = "";
|
534 |
+
}
|
535 |
+
|
536 |
+
$remarketing_id = $product_id;
|
537 |
+
$product_sku = $product->get_sku();
|
538 |
+
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
|
539 |
+
$remarketing_id = $product_sku;
|
540 |
+
}
|
541 |
+
|
542 |
+
$dataLayer["ecommerce"]["add"]["products"][] = array(
|
543 |
+
"name" => $product->get_title(),
|
544 |
+
"id" => $remarketing_id,
|
545 |
+
"price" => $product->get_price(),
|
546 |
+
"category" => $product_cat,
|
547 |
+
"quantity" => $cart_item["quantity"]
|
548 |
+
);
|
549 |
+
|
550 |
+
if ( "variation" == $product->get_type() ) {
|
551 |
+
$dataLayer["ecommerce"]["add"][0][ "variant" ] = implode(",", $product->get_variation_attributes());
|
552 |
+
}
|
553 |
+
}
|
554 |
+
|
555 |
+
gtm4wp_woocommerce_addjs( "document.cookie = 'gtm4wp_product_readded_to_cart=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';" );
|
556 |
+
unset( $_COOKIE[ "gtm4wp_product_readded_to_cart" ] );
|
557 |
+
}
|
558 |
+
|
559 |
return $dataLayer;
|
560 |
}
|
561 |
|
571 |
return;
|
572 |
}
|
573 |
|
574 |
+
$product_id = $product->get_id();
|
575 |
+
|
576 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
577 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
578 |
$product_cat = array_pop( $_product_cats );
|
579 |
$product_cat = $product_cat->name;
|
581 |
$product_cat = "";
|
582 |
}
|
583 |
|
|
|
584 |
$remarketing_id = $product_id;
|
585 |
$product_sku = $product->get_sku();
|
586 |
if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) {
|
589 |
|
590 |
$_temp_productdata = array(
|
591 |
"id" => $remarketing_id,
|
592 |
+
"name" => $product->get_title(),
|
593 |
"sku" => $product_sku ? __( 'SKU:', 'duracelltomi-google-tag-manager' ) . ' ' . $product_sku : $product_id,
|
594 |
"category" => $product_cat,
|
595 |
"price" => $product->get_price(),
|
717 |
$( '.gtm4wp_productdata' ).each( function() {
|
718 |
productdata = jQuery( this );
|
719 |
|
720 |
+
". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push( '".gtm4wp_prefix_productid("")."' + productdata.data( 'gtm4wp_product_id' ) );
|
721 |
});
|
722 |
}
|
723 |
})(jQuery);
|
865 |
global $product, $woocommerce_loop, $wp_query, $gtm4wp_options;
|
866 |
|
867 |
$product_id = $product->get_id();
|
868 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
869 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
870 |
$product_cat = array_pop( $_product_cats );
|
871 |
$product_cat = $product_cat->name;
|
895 |
|
896 |
$_temp_productdata = array(
|
897 |
"id" => $remarketing_id,
|
898 |
+
"name" => $product->get_title(),
|
899 |
"category" => $product_cat,
|
900 |
"price" => $product->get_price(),
|
901 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
903 |
"listname" => $list_name
|
904 |
);
|
905 |
|
906 |
+
if ( "variation" == $product->get_type() ) {
|
907 |
$_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
|
908 |
} else {
|
909 |
$_temp_productdata[ "variant" ] = "";
|
930 |
global $gtm4wp_options;
|
931 |
|
932 |
$product_id = $product->get_id();
|
933 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
934 |
if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
|
935 |
$product_cat = array_pop( $_product_cats );
|
936 |
$product_cat = $product_cat->name;
|
946 |
|
947 |
$_temp_productdata = array(
|
948 |
"id" => $remarketing_id,
|
949 |
+
"name" => $product->get_title(),
|
950 |
"price" => $product->get_price(),
|
951 |
"category" => $product_cat,
|
952 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0)
|
953 |
);
|
954 |
|
955 |
+
if ( "variation" == $product->get_type() ) {
|
956 |
$_temp_productdata[ "variant" ] = implode(",", $product->get_variation_attributes());
|
957 |
} else {
|
958 |
$_temp_productdata[ "variant" ] = "";
|
1012 |
|
1013 |
if ( "content-widget-product.php" == $template_name ) {
|
1014 |
$product_id = $product->get_id();
|
1015 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
1016 |
if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) {
|
1017 |
$product_cat = array_pop( $_product_cats );
|
1018 |
$product_cat = $product_cat->name;
|
1028 |
|
1029 |
$_temp_productdata = array(
|
1030 |
"id" => $remarketing_id,
|
1031 |
+
"name" => $product->get_title(),
|
1032 |
"price" => $product->get_price(),
|
1033 |
"category" => $product_cat,
|
1034 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
1114 |
$cat_obj = $wp_query->get_queried_object();
|
1115 |
$product_cat = $cat_obj->name;
|
1116 |
} else {
|
1117 |
+
$_product_cats = get_the_terms($product_id, 'product_cat');
|
1118 |
if ( ( is_array($_product_cats) ) && ( count( $_product_cats ) > 0 ) ) {
|
1119 |
$last_product_cat = array_pop( $_product_cats );
|
1120 |
$product_cat = $last_product_cat->name;
|
1143 |
|
1144 |
$_temp_productdata = array(
|
1145 |
"id" => $remarketing_id,
|
1146 |
+
"name" => $product->get_title(),
|
1147 |
"price" => $product->get_price(),
|
1148 |
"category" => $product_cat,
|
1149 |
"productlink" => apply_filters( 'the_permalink', get_permalink(), 0),
|
1163 |
);
|
1164 |
}
|
1165 |
|
1166 |
+
function gtm4wp_woocommerce_cart_item_restored( $cart_item_key ) {
|
1167 |
+
global $woocommerce;
|
1168 |
+
|
1169 |
+
setcookie( "gtm4wp_product_readded_to_cart", $cart_item_key );
|
1170 |
+
}
|
1171 |
+
|
1172 |
// do not add filter if someone enabled WooCommerce integration without an activated WooCommerce plugin
|
1173 |
if ( isset ( $GLOBALS["woocommerce"] ) ) {
|
1174 |
add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "gtm4wp_woocommerce_datalayer_filter_items" );
|
1198 |
add_action( 'woocommerce_shortcode_before_top_rated_products_loop', 'gtm4wp_before_top_rated_products_loop' );
|
1199 |
add_action( 'woocommerce_shortcode_before_featured_products_loop', 'gtm4wp_before_featured_products_loop' );
|
1200 |
add_action( 'woocommerce_shortcode_before_related_products_loop', 'gtm4wp_before_related_products_loop' );
|
1201 |
+
add_action( 'woocommerce_cart_item_restored', 'gtm4wp_woocommerce_cart_item_restored' );
|
1202 |
}
|
1203 |
}
|
js/admin-subtabs.js
CHANGED
@@ -64,6 +64,10 @@ var adminsubtabs = {
|
|
64 |
"int-wc": {
|
65 |
tabtext: gtm4wp.wctabtitle,
|
66 |
numitems: 6
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
}
|
69 |
};
|
64 |
"int-wc": {
|
65 |
tabtext: gtm4wp.wctabtitle,
|
66 |
numitems: 6
|
67 |
+
},
|
68 |
+
"int-google-optimize": {
|
69 |
+
tabtext: gtm4wp.gotabtitle,
|
70 |
+
numitems: 2
|
71 |
}
|
72 |
}
|
73 |
};
|
public/frontend.php
CHANGED
@@ -21,7 +21,7 @@ function gtm4wp_is_assoc($arr) {
|
|
21 |
|
22 |
if ( !function_exists( "getallheaders") ) {
|
23 |
function getallheaders() {
|
24 |
-
$headers =
|
25 |
foreach ( $_SERVER as $name => $value ) {
|
26 |
if ( substr($name, 0, 5) == "HTTP_" ) {
|
27 |
$headers[ str_replace(' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
|
@@ -599,7 +599,7 @@ function gtm4wp_wp_header_begin() {
|
|
599 |
' . $gtm4wp_datalayer_name . '.push(' . str_replace(
|
600 |
array( '"-~-', '-~-"' ),
|
601 |
array( "", "" ),
|
602 |
-
str_replace( "
|
603 |
) . ');';
|
604 |
}
|
605 |
|
@@ -660,3 +660,7 @@ if ( isset( $GLOBALS[ "gtm4wp_options" ] ) && ( $GLOBALS[ "gtm4wp_options" ][ GT
|
|
660 |
&& isset ( $GLOBALS["woocommerce"] ) ) {
|
661 |
require_once( dirname( __FILE__ ) . "/../integration/woocommerce.php" );
|
662 |
}
|
|
|
|
|
|
|
|
21 |
|
22 |
if ( !function_exists( "getallheaders") ) {
|
23 |
function getallheaders() {
|
24 |
+
$headers = [];
|
25 |
foreach ( $_SERVER as $name => $value ) {
|
26 |
if ( substr($name, 0, 5) == "HTTP_" ) {
|
27 |
$headers[ str_replace(' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
|
599 |
' . $gtm4wp_datalayer_name . '.push(' . str_replace(
|
600 |
array( '"-~-', '-~-"' ),
|
601 |
array( "", "" ),
|
602 |
+
str_replace( "", "-", $dl_json_data )
|
603 |
) . ');';
|
604 |
}
|
605 |
|
660 |
&& isset ( $GLOBALS["woocommerce"] ) ) {
|
661 |
require_once( dirname( __FILE__ ) . "/../integration/woocommerce.php" );
|
662 |
}
|
663 |
+
|
664 |
+
if ( isset( $GLOBALS[ "gtm4wp_options" ] ) && ( $GLOBALS[ "gtm4wp_options" ][ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] != "" ) ) {
|
665 |
+
require_once( dirname( __FILE__ ) . "/../integration/google-optimize.php" );
|
666 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: duracelltomi
|
|
3 |
Donate link: https://duracelltomi.com/
|
4 |
Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel
|
5 |
Requires at least: 3.4.0
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
@@ -271,10 +271,20 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
|
|
271 |
|
272 |
== Changelog ==
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
= 1.6.1 =
|
275 |
|
276 |
-
Fixed: PHP warning message on WooCommerce cart page
|
277 |
-
Fixed: Better compatibility with WooCommerce 2.6.x :-)
|
278 |
|
279 |
= 1.6 =
|
280 |
|
@@ -286,7 +296,7 @@ Fixed: Better compatibility with WooCommerce 2.6.x :-)
|
|
286 |
|
287 |
= 1.5.1 =
|
288 |
|
289 |
-
Fixed: clicks on products in product list pages redirected to undefined URLs with some themes.
|
290 |
|
291 |
= 1.5 =
|
292 |
|
@@ -483,6 +493,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
|
|
483 |
|
484 |
== Upgrade Notice ==
|
485 |
|
|
|
|
|
|
|
|
|
486 |
= 1.6.1 =
|
487 |
|
488 |
Bugfix release.
|
3 |
Donate link: https://duracelltomi.com/
|
4 |
Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, adwords remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel
|
5 |
Requires at least: 3.4.0
|
6 |
+
Tested up to: 4.8.1
|
7 |
+
Stable tag: 1.7
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
271 |
|
272 |
== Changelog ==
|
273 |
|
274 |
+
= 1.7 =
|
275 |
+
|
276 |
+
* Updated: even better WooCommerce 3.0 compatibility (WooCommerce 2.6 still supported but this support ends with the next plugin version)
|
277 |
+
* Fixed: properly escaping product category name on variable product detail pages
|
278 |
+
* Fixed: proper data layer stucture in the gtm4wp.changeDetailViewEEC event
|
279 |
+
* Added: Google Optimize page hiding snippet under Integrations tab
|
280 |
+
* Added: add to cart data for WooCommerce enhanced ecommerce tracking if user undos a cart item removal (no need to update GTM tags)
|
281 |
+
* Added: you can now enter a product ID prefix so that IDs can match with IDs in some product feeds generated by other plugins
|
282 |
+
* Added: option to track cart page as step 1 in enhanced ecommerce checkout funnel
|
283 |
+
|
284 |
= 1.6.1 =
|
285 |
|
286 |
+
* Fixed: PHP warning message on WooCommerce cart page
|
287 |
+
* Fixed: Better compatibility with WooCommerce 2.6.x :-)
|
288 |
|
289 |
= 1.6 =
|
290 |
|
296 |
|
297 |
= 1.5.1 =
|
298 |
|
299 |
+
* Fixed: clicks on products in product list pages redirected to undefined URLs with some themes.
|
300 |
|
301 |
= 1.5 =
|
302 |
|
493 |
|
494 |
== Upgrade Notice ==
|
495 |
|
496 |
+
= 1.7 =
|
497 |
+
|
498 |
+
Better WooCommerce 3.x compatibility and new features
|
499 |
+
|
500 |
= 1.6.1 =
|
501 |
|
502 |
Bugfix release.
|