From 83d1a2a37e6aba3f10cc5ecb8889497ca35c0c4e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 18 Sep 2019 23:42:56 +0200 Subject: [PATCH] fix empty page title, extract ecommerce tracking --- .../d3_oxcmp_utils_googleanalytics.php | 28 ++- .../views/tpl/widget/d3ga_gtag.tpl | 166 +----------------- .../tpl/widget/inc/d3ga_gtag_ecommerce.tpl | 161 +++++++++++++++++ 3 files changed, 185 insertions(+), 170 deletions(-) diff --git a/copy_this/modules/d3/d3_googleanalytics/modules/components/d3_oxcmp_utils_googleanalytics.php b/copy_this/modules/d3/d3_googleanalytics/modules/components/d3_oxcmp_utils_googleanalytics.php index 558c059..b7ab125 100644 --- a/copy_this/modules/d3/d3_googleanalytics/modules/components/d3_oxcmp_utils_googleanalytics.php +++ b/copy_this/modules/d3/d3_googleanalytics/modules/components/d3_oxcmp_utils_googleanalytics.php @@ -1,9 +1,13 @@ addTplParam('oD3GAActCurrency', Registry::getConfig()->getActShopCurrencyObject()); $oParentView->addTplParam('sD3GAPageLocation', $oParentView->getBaseLink()); $oParentView->addTplParam('sD3GAPagePath', str_replace(Registry::getConfig()->getShopUrl(), '', $oParentView->getBaseLink())); - $oParentView->addTplParam('sD3GAPageTitle', $oParentView->getTitle()); - + // prevent overwriting with empty title from later loaded widgets + if ($oParentView->getTitle() && false == $oParentView->getViewDataElement('sD3GAPageTitle')) { + $oParentView->addTplParam('sD3GAPageTitle', $oParentView->getTitle()); + } if (Registry::getSession()->getUser() && ($sUserId = Registry::getSession()->getUser()->getId())) { $oParentView->addTplParam('sD3GAUserId', md5($sUserId)); } @@ -114,9 +126,9 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare { if (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'async') { return 'd3_googleanalytics.tpl'; - } elseif (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'universaal') { + } elseif (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'universaal') { return 'd3ga_universal.tpl'; - } elseif (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { + } elseif (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { return 'd3ga_gtag.tpl'; } } @@ -244,7 +256,7 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare { $aParameter = array(); - if (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { + if (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { $aParameter = $this->_d3getCreateAnonymizeIpParameter($aParameter); /** @var oxUBase $oCurrentView */ @@ -274,9 +286,9 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare { if (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'async') { return $this->_d3getAsyncSendpageViewParameters(); - } elseif (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'universal') { + } elseif (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'universal') { return $this->_d3getUniversalSendPageViewParameters(); - } elseif (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { + } elseif (d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { return $this->_d3getGtagSendPageViewParameters(); } } @@ -558,7 +570,7 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare */ protected function _d3getCreateAnonymizeIpParameter($aParameter) { - if (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('blD3GAAnonymizeIP')) { + if (d3_cfg_mod::get($this->_sModId)->getValue('blD3GAAnonymizeIP')) { $aParameter[] = "'anonymize_ip': true'"; } diff --git a/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl index 20a03f4..c96d774 100644 --- a/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl +++ b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl @@ -109,6 +109,7 @@ } [{/if}] + [{* track page load time *}] [{if $oD3GASettings->getValue('blD3GATrackPageLoadTime')}] [{block name="d3ga_trackpageloadtime"}] let perfData = window.performance.timing; @@ -125,8 +126,7 @@ [{/block}] [{/if}] - - [{* bounce optimization*}] + [{* bounce optimization *}] [{block name="d3ga_bounceoptimization"}] [{if $oD3GASettings->getValue('blUseBounceRateOptimization')}] setTimeout("gtag('event', 'NoBounce', {" + @@ -151,6 +151,8 @@ [{/if}] [{/block}] + [{include file="d3ga_gtag_ecommerce.tpl"}] + [{* https://developers.google.com/analytics/devguides/collection/gtagjs/events *}] [{* login, logout, toBasket, fromBasket, sendContact *}] gtag('event', 'ACTION', { 'event_category': 'CATEGORY', 'event_label': 'LABEL', 'value': 'VALUE' }); @@ -159,164 +161,6 @@ gtag('event', 'ACTION', { 'event_category': 'CATEGORY', 'event_label': 'LABEL', [{* https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets *}] gtag ('event', 'age_dimension', {'age': 12}); -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/ecommerce *}] -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'purchase', { - "transaction_id": "24.031608523954162", - "affiliation": "Google online store", - "value": 23.07, - "currency": "USD", - "tax": 1.24, - "shipping": 0, - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - }, - { - "id": "P67890", - "name": "Flame challenge TShirt", - "list_name": "Search Results", - "brand": "MyBrand", - "category": "Apparel/T-Shirts", - "variant": "Red", - "list_position": 2, - "quantity": 1, - "price": '3.0' - } - ] - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'view_item_list', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": 2 - }, - { - "id": "P67890", - "name": "Flame challenge TShirt", - "list_name": "Search Results", - "brand": "MyBrand", - "category": "Apparel/T-Shirts", - "variant": "Red", - "list_position": 2, - "quantity": 1, - "price": 3 - } - ] - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'view_item', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - } - ] - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'add_to_cart', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - } - ] - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'remove_from_cart', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - } - ] - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'begin_checkout', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - } - ], - "coupon": "" - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'checkout_progress', { - "items": [ - { - "id": "P12345", - "name": "Android Warhol T-Shirt", - "list_name": "Search Results", - "brand": "Google", - "category": "Apparel/T-Shirts", - "variant": "Black", - "list_position": 1, - "quantity": 2, - "price": '2.0' - } - ], - "coupon": "SUMMER_DISCOUNT" - }); - -[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] - gtag('event', 'set_checkout_option', { - "checkout_step": 1, - "checkout_option": "shipping method", - "value": "USPS" - }); - - --------------------------------------------------------------------- @@ -342,8 +186,6 @@ gtag('event', 'ACTION', { 'event_category': 'CATEGORY', 'event_label': 'LABEL', [{include file="d3ga_universal_adwords.tpl"}] [{include file="d3ga_universal_custom.tpl"}] - - [{*[{include file="d3ga_universal_ecommerce.tpl"}]*}] [{*/strip*}] diff --git a/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl index ef15099..87dbf7b 100644 --- a/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl +++ b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl @@ -1,3 +1,164 @@ +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/ecommerce *}] +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'purchase', { + "transaction_id": "24.031608523954162", + "affiliation": "Google online store", + "value": 23.07, + "currency": "USD", + "tax": 1.24, + "shipping": 0, + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + }, + { + "id": "P67890", + "name": "Flame challenge TShirt", + "list_name": "Search Results", + "brand": "MyBrand", + "category": "Apparel/T-Shirts", + "variant": "Red", + "list_position": 2, + "quantity": 1, + "price": '3.0' + } + ] +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'view_item_list', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": 2 + }, + { + "id": "P67890", + "name": "Flame challenge TShirt", + "list_name": "Search Results", + "brand": "MyBrand", + "category": "Apparel/T-Shirts", + "variant": "Red", + "list_position": 2, + "quantity": 1, + "price": 3 + } + ] +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'view_item', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + } + ] +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'add_to_cart', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + } + ] +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'remove_from_cart', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + } + ] +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'begin_checkout', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + } + ], + "coupon": "" +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'checkout_progress', { + "items": [ + { + "id": "P12345", + "name": "Android Warhol T-Shirt", + "list_name": "Search Results", + "brand": "Google", + "category": "Apparel/T-Shirts", + "variant": "Black", + "list_position": 1, + "quantity": 2, + "price": '2.0' + } + ], + "coupon": "SUMMER_DISCOUNT" +}); + +[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] +gtag('event', 'set_checkout_option', { + "checkout_step": 1, + "checkout_option": "shipping method", + "value": "USPS" +}); + + +[{* ============================================================ *}] + + [{if $oD3GASettings->getValue('blD3GASendECommerce') && $oViewConf->getActiveClassName() == 'thankyou'}][{strip}] [{block name="UniversalEcommerceOrder"}] [{assign var="order" value=$oView->getOrder()}]