diff --git a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php index b3dfff0..30c7397 100644 --- a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php +++ b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php @@ -32,10 +32,6 @@ class d3_cfg_googleanalytics_adwords extends d3_cfg_mod_main */ public function getGaType() { - if ($this->d3GetSet()->getValue('sD3GAType') == 'async') { - return 'async'; - } - - return 'universal'; + return $this->d3GetSet()->getValue('sD3GAType'); } } diff --git a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php index 6feef4e..cef8584 100644 --- a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php +++ b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php @@ -32,10 +32,6 @@ class d3_cfg_googleanalytics_campaigns extends d3_cfg_mod_main */ public function getGaType() { - if ($this->d3GetSet()->getValue('sD3GAType') == 'async') { - return 'async'; - } - - return 'universal'; + return $this->d3GetSet()->getValue('sD3GAType'); } } diff --git a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php index ef34c9a..ef00096 100644 --- a/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php +++ b/copy_this/modules/d3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php @@ -32,10 +32,6 @@ class d3_cfg_googleanalytics_main extends d3_cfg_mod_main */ public function getGaType() { - if ($this->d3GetSet()->getValue('sD3GAType') == 'async') { - return 'async'; - } - - return 'universal'; + return $this->d3GetSet()->getValue('sD3GAType'); } } diff --git a/copy_this/modules/d3/d3_googleanalytics/metadata.php b/copy_this/modules/d3/d3_googleanalytics/metadata.php index ee203f2..836db15 100644 --- a/copy_this/modules/d3/d3_googleanalytics/metadata.php +++ b/copy_this/modules/d3/d3_googleanalytics/metadata.php @@ -92,14 +92,13 @@ $aModule = array( 'd3ga_universal_trustedstore.tpl' => 'd3/d3_googleanalytics/views/tpl/widget/inc/d3ga_universal_trustedstore.tpl', - 'd3_cfg_googleanalytics_main.tpl' => - 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl', - 'd3_cfg_googleanalytics_adwords.tpl' => - 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_adwords.tpl', - 'd3_cfg_googleanalytics_campaigns.tpl' => - 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_campaigns.tpl', - 'd3_cfg_googleanalytics_trustedstore.tpl' => - 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_trustedstore.tpl', + 'd3ga_gtag.tpl' => 'd3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl', + 'd3ga_gtag_ecommerce.tpl' => 'd3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl', + + 'd3_cfg_googleanalytics_main.tpl' => 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl', + 'd3_cfg_googleanalytics_adwords.tpl' => 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_adwords.tpl', + 'd3_cfg_googleanalytics_campaigns.tpl' => 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_campaigns.tpl', + 'd3_cfg_googleanalytics_trustedstore.tpl' => 'd3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_trustedstore.tpl', ), 'events' => array( 'onActivate' => 'd3install::checkUpdateStart', 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 fbee324..8242c9d 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,5 +1,9 @@ _sModId)->getValue('sD3GAType') == 'async') { return 'd3_googleanalytics.tpl'; + } elseif (\D3\ModCfg\Application\Model\Configuration\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') { + return 'd3ga_gtag.tpl'; } - - return 'd3ga_universal.tpl'; } /** @@ -226,6 +232,16 @@ 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') { + $aParameter = $this->_d3getCreateAnonymizeIpParameter($aParameter); + + /** @var oxUBase $oCurrentView */ + $oCurrentView = oxRegistry::getConfig()->getActiveView(); + $oCurrentView->getIsOrderStep(); + + $aParameter = $this->_d3getGtagSendPageViewPageParameter($oCurrentView, $aParameter); + } + $aParameter = $this->_d3getCreateDomainNameParameter($aParameter); $aParameter = $this->_d3getCreateCookiePathParameter($aParameter); $aParameter = $this->_d3getCreateDomainLinkerParameter($aParameter); @@ -246,9 +262,11 @@ 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') { + return $this->_d3getUniversalSendPageViewParameters(); + } elseif (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('sD3GAType') == 'gtag') { + return $this->_d3getGtagSendPageViewParameters(); } - - return $this->_d3getUniversalSendPageViewParameters(); } /** @@ -292,6 +310,11 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare return ''; } + protected function _d3getGtagSendPageViewParameters() + { + return ''; + } + /** * @return bool */ @@ -514,6 +537,22 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare return $aParameter; } + /** + * @param $aParameter + * @return array + * @throws DBALException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + */ + protected function _d3getCreateAnonymizeIpParameter($aParameter) + { + if (\D3\ModCfg\Application\Model\Configuration\d3_cfg_mod::get($this->_sModId)->getValue('blD3GAAnonymizeIP')) { + $aParameter[] = "'anonymize_ip': true'"; + } + + return $aParameter; + } + /** * @param oxUBase $oCurrentView * @param array $aParameter @@ -540,18 +579,14 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare * * @return array */ - protected function _d3getUniversalSendPageViewPageParameter($oCurrentView, $aParameter) + protected function _d3getGtagSendPageViewPageParameter($oCurrentView, $aParameter) { if ($oCurrentView->getIsOrderStep() || strtolower($oCurrentView->getClassName()) == 'thankyou') { - $aParameter[] = "'page': '/{$oCurrentView->getClassName()}.html'"; - $aParameter[] = "'title': 'Checkout: " . ucfirst($oCurrentView->getClassName()) . "'"; - - return $aParameter; + $aParameter[] = "'page_path': '/{$oCurrentView->getClassName()}.html'"; + $aParameter[] = "'page_title': 'Checkout: " . ucfirst($oCurrentView->getClassName()) . "'"; } elseif ($this->_d3HasNoPageParameter()) { - $aParameter[] = "'page': '/{$oCurrentView->getClassName()}.html'"; - $aParameter[] = "'title': '" . ucfirst($oCurrentView->getClassName()) . "'"; - - return $aParameter; + $aParameter[] = "'page_path': '/{$oCurrentView->getClassName()}.html'"; + $aParameter[] = "'page_title': '" . ucfirst($oCurrentView->getClassName()) . "'"; } return $aParameter; diff --git a/copy_this/modules/d3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl b/copy_this/modules/d3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl index 2995419..9ad28e3 100644 --- a/copy_this/modules/d3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl +++ b/copy_this/modules/d3/d3_googleanalytics/views/admin/tpl/d3_cfg_googleanalytics_main.tpl @@ -142,7 +142,8 @@
- getGaType() != 'async'}]checked[{/if}] onclick="alert('[{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_UNIVERSAL_DESC"}]');"> [{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_UNIVERSAL"}]
+ getGaType() == 'gtag'}]checked[{/if}]> [{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_GTAG"}]
+ getGaType() == 'universal'}]checked[{/if}] onclick="alert('[{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_UNIVERSAL_DESC"}]');"> [{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_UNIVERSAL"}]
getGaType() == 'async'}]checked[{/if}] onclick="alert('[{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_ASYNC_DESC"}]');"> [{oxmultilang ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_ASYNC"}] [{oxinputhelp ident="D3_GOOGLEANALYTICS_MAIN_GATYPE_DESC"}]
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 new file mode 100644 index 0000000..076e12d --- /dev/null +++ b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/d3ga_gtag.tpl @@ -0,0 +1,354 @@ +[{if $blD3GoogleAnalyticsActive && $oD3GASettings->getValue('sD3GAId')}] + [{capture name="d3GATrackCode"}] + [{strip}] + [{if $oD3GASettings->getValue('blD3GAUseOptOut')}] + [{block name="d3ga_optoutscript"}] + + [{/block}] + [{/if}] + +## nach head ## https://developers.google.com/analytics/devguides/collection/gtagjs/ + + + + +--------------------------------------------------------------------- + + + + + + + + [{/strip}] + [{/capture}] + + [{if $oViewConf->getActiveClassName() == 'thankyou'}] + [{$oView->logCode($smarty.capture.d3GATrackCode)}] + [{/if}] + + [{$smarty.capture.d3GATrackCode}] +[{/if}] \ No newline at end of file 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 new file mode 100644 index 0000000..ef15099 --- /dev/null +++ b/copy_this/modules/d3/d3_googleanalytics/views/tpl/widget/inc/d3ga_gtag_ecommerce.tpl @@ -0,0 +1,46 @@ +[{if $oD3GASettings->getValue('blD3GASendECommerce') && $oViewConf->getActiveClassName() == 'thankyou'}][{strip}] + [{block name="UniversalEcommerceOrder"}] + [{assign var="order" value=$oView->getOrder()}] + + [{assign var="currate" value=$order->oxorder__oxcurrate->value}] + [{if $oD3GASettings->getValue('blD3GAUseNetto')}] + [{math equation="s / r" s=$order->getOrderNetSum() r=$currate format="%.2f" assign="sTotal"}] [{* // total - required - has to be gross sum *}] + [{else}] + [{math equation="s / r" s=$order->getTotalOrderSum() r=$currate format="%.2f" assign="sTotal"}] [{* // total - required *}] + [{/if}] + [{math equation="s - r" s=$order->getTotalOrderSum() r=$order->getOrderNetSum() format="%.2f" assign="sTax"}] + [{math equation="s / r" s=$order->oxorder__oxdelcost->value r=$currate format="%.2f" assign="sShipping"}] + + gtag('event', 'purchase', { + "transaction_id": "[{$order->oxorder__oxordernr->value}]", + "affiliation": "[{$oxcmp_shop->oxshops__oxname->value|escape:"quotes"}]", + "value": [{$sTotal}], + "currency": "[{$order->getFieldData('oxcurrency')}]", + "tax": [{$sTax}], + "shipping": [{$sShipping}], + "items": [ + + [{foreach from=$order->getOrderArticles() item=oOrderArticle name="artList"}] + [{block name="UniversalEcommerceOrderArticle"}] + [{if $oD3GASettings->getValue('blD3GAUseNetto')}] + [{assign var="oPrice" value=$oOrderArticle->getPrice()}] + [{math equation="s / r" s=$oPrice->getNettoPrice() r=$currate format="%.2f" assign="sPrice"}] + [{else}] + [{assign var="sPrice" value=$oOrderArticle->oxorderarticles__oxprice->value}] + [{/if}] + { + "id": "[{$order->oxorder__oxordernr->value}]", + "name": "[{$oOrderArticle->oxorderarticles__oxtitle->value|escape:"quotes"}]", + "list_name": "Search Results", + "brand": "Google", + "category": "[{$oOrderArticle->oxorderarticles__d3_galocator->value|escape:"quotes"}]", + "variant": "[{$oOrderArticle->oxorderarticles__oxselvariant->value}]", + "list_position": [{$smarty.foreach.artList.index}], + "quantity": [{$oOrderArticle->oxorderarticles__oxamount->value}], + "price": '[{$sPrice}]' + }, + [{/block}] + [{/foreach}] + }); + [{/block}] +[{/strip}][{/if}]