fix empty page title, extract ecommerce tracking

This commit is contained in:
Daniel Seifert 2019-09-18 23:42:56 +02:00 committed by Daniel Seifert
parent 03d7c12f1d
commit 83d1a2a37e
3 changed files with 185 additions and 170 deletions

View File

@ -1,9 +1,13 @@
<?php
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
/**
@ -45,6 +49,12 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
/**
* @return null
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
* @throws StandardException
*/
public function render()
{
@ -60,8 +70,10 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
$oParentView->addTplParam('oD3GAActCurrency', Registry::getConfig()->getActShopCurrencyObject());
$oParentView->addTplParam('sD3GAPageLocation', $oParentView->getBaseLink());
$oParentView->addTplParam('sD3GAPagePath', str_replace(Registry::getConfig()->getShopUrl(), '', $oParentView->getBaseLink()));
// 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'";
}

View File

@ -109,6 +109,7 @@
}
[{/if}]
[{* track page load time *}]
[{if $oD3GASettings->getValue('blD3GATrackPageLoadTime')}]
[{block name="d3ga_trackpageloadtime"}]
let perfData = window.performance.timing;
@ -125,7 +126,6 @@
[{/block}]
[{/if}]
[{* bounce optimization *}]
[{block name="d3ga_bounceoptimization"}]
[{if $oD3GASettings->getValue('blUseBounceRateOptimization')}]
@ -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"
});
</script>
---------------------------------------------------------------------
@ -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"}]*}]
</script>
[{*/strip*}]

View File

@ -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()}]