Compare commits

...

7 Commits
1.4.0 ... 1.5.0

Author SHA1 Message Date
MaxBUhe dfdc5d5edf bump version && changelog to 1.5.0 2023-05-23 11:44:07 +02:00
MaxBUhe ae6f9bfaa9 switch php-file-header hint 2023-05-23 10:49:59 +02:00
MaxBUhe 1d9e09b8b1 switch view_item and item_list template 2023-05-23 10:49:05 +02:00
MaxBUhe f9a0834d26 add settings-entry; add consentmanager-option 2023-05-16 14:42:12 +02:00
MaxBUhe bb70cda626 fix unnecessary convert of int to str 2023-05-16 14:41:47 +02:00
MaxBUhe c9a1174c98 genuine code cleanup; switch hard-getter to methods and use price-object
# Conflicts:
#	Application/views/blocks/view_item.tpl
#	Application/views/ga4/add_to_cart.tpl
2023-05-16 14:41:32 +02:00
Christoph Staeblein f3b2911679 OXID UserCentrics support, general overhaul for cookie managers 2023-05-16 14:24:50 +02:00
12 changed files with 122 additions and 121 deletions

View File

@ -1,16 +1,13 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
* http://www.shopmodule.com
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
$style = '<style type="text/css">
@ -34,5 +31,8 @@ $aLang = [
// for cookie manager settings
'SHOP_MODULE_GROUP_d3_gtm_settings_cookiemanager' => 'Cookie Manager Einstellungen',
'SHOP_MODULE_d3_gtm_settings_hasOwnCookieManager' => 'Cookie Manager nutzen?',
'SHOP_MODULE_d3_gtm_settings_cookieName' => 'CookieID',
'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER' => 'Nutzen Sie die Consentmanager-Einbindung?',
'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER_NO' => 'Nein',
'SHOP_MODULE_d3_gtm_settings_HAS_CONSENTMANAGER_YES' => 'Ja',
'SHOP_MODULE_d3_gtm_settings_cookieName' => 'CookieID',
];

View File

@ -2,10 +2,10 @@
[{*$oxcmp_basket|get_class_methods|dumpvar*}]
[{assign var="d3BasketPrice" value=$oxcmp_basket->getPrice()}]
[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}]
[{strip}][{capture assign=d3_ga4_view_cart}]
let iPrice = "[{oxprice price=$oxcmp_basket->getPrice()}]";
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'view_cart',
@ -13,15 +13,15 @@
'ecommerce': {
'actionField': "step: 1",
'currency': "[{$currency->name}]",
'value': iPrice.replace("€", ""),
'value': [{$d3BasketPrice->getPrice()}],
'items': [
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
[{assign var='_price' value=$basketitem->getUnitPrice()}]
[{assign var="d3oItemPrice" value=$basketitem->getPrice()}]
{
'item_id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
'item_name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
'item_variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
'price': [{$_price->getPrice()}],
'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]',
'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]',
'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]',
'price': [{$d3oItemPrice->getPrice()}],
'quantity':[{$basketitem->getAmount()}],
'position':[{$smarty.foreach.gtmCartContents.index}]
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]

View File

@ -10,21 +10,22 @@
'event': 'purchase',
'eventLabel':'Checkout Step 5',
'ecommerce': {
'transaction_id': '[{$_gtmOrder->oxorder__oxordernr->value}]',
'affiliation': '[{$oxcmp_shop->oxshops__oxname->value}]',
'value': '[{$_gtmOrder->oxorder__oxtotalordersum->value}]',
'tax': '[{math equation="x+y" x=$_gtmOrder->oxorder__oxartvatprice1->value y=$_gtmOrder->oxorder__oxartvatprice2->value }]',
'shipping': '[{$_gtmOrder->oxorder__oxdelcost->value}]',
'transaction_id': '[{$_gtmOrder->getFieldData("oxordernr")}]',
'affiliation': '[{$oxcmp_shop->getFieldData("oxname")}]',
'value': [{$_gtmOrder->getTotalOrderSum()}],
'tax': [{math equation="x+y" x=$_gtmOrder->getFieldData("oxartvatprice1") y=$_gtmOrder->getFieldData("oxartvatprice2") }],
'shipping': [{$_gtmOrder->getFieldData("oxdelcost")}],
'currency': '[{$_gtmOrder->getFieldData('oxcurrency')}]',
'items':
[
[{foreach from=$_gtmArticles item="_gtmArticle" name="gtmArticles"}]
[{foreach from=$_gtmArticles item="d3BasketArticle" name="gtmArticles"}]
[{assign var="d3oArticlePrice" value=$d3BasketArticle->getPrice()}]
{
'id': '[{$_gtmArticle->oxorderarticles__oxartnum->value}]',
'name': '[{$_gtmArticle->oxorderarticles__oxtitle->value}]',
'variant': '[{$_gtmArticle->oxorderarticles__oxselvariant->value}]',
'price': [{$_gtmArticle->oxorderarticles__oxprice->value}],
'quantity': [{$_gtmArticle->oxorderarticles__oxamount->value}],
'id': '[{$d3BasketArticle->getFieldData("oxartnum")}]',
'name': '[{$d3BasketArticle->getFieldData("oxtitle")}]',
'variant': '[{$d3BasketArticle->getFieldData("oxselvariant")}]',
'price': [{$d3oArticlePrice->getPrice()}],
'quantity': [{$d3BasketArticle->getFieldData("oxamount")}],
'position': [{$smarty.foreach.gtmArticles.iteration}]
}[{if !$smarty.foreach.gtmArticles.last}],[{/if}]
[{/foreach}]

View File

@ -1,25 +0,0 @@
[{$smarty.block.parent}]
[{assign var="gtmProduct" value=$oView->getProduct()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'view_item',
'eventLabel':'Product View',
'ecommerce': {
'currency': '[{$currency->name}]',
'items': [
{
'item_name': '[{$gtmProduct->oxarticles__oxtitle->value}]',
'item_id': '[{$gtmProduct->oxarticles__oxartnum->value}]',
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'item_variant': '[{if $gtmProduct->oxarticles__oxvarselect->value}][{$gtmProduct->oxarticles__oxvarselect->value}][{/if}]',
'price': [{$gtmProduct->oxarticles__oxprice->value}]
}
]
}
});
</script>

View File

@ -0,0 +1,26 @@
[{$smarty.block.parent}]
[{assign var="gtmProduct" value=$oView->getProduct()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'view_item',
'eventLabel':'Product View',
'ecommerce': {
'currency': '[{$currency->name}]',
'items': [
{
'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]',
'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]',
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'item_variant': '[{if $gtmProduct->getFieldData("oxvarselect")}][{$gtmProduct->getFieldData("oxvarselect")}][{/if}]',
[{assign var="d3PriceObject" value=$gtmProduct->getPrice()}]
'price': [{$d3PriceObject->getPrice()}]
}
]
}
});
</script>

View File

@ -1,35 +0,0 @@
[{$smarty.block.parent}]
[{assign var="gtmProduct" value=$oView->getProduct()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'ee.impression',
'eventLabel':'Impression',
'ecommerce': {
'currencyCode': '[{$currency->name}]',
'impressions': [
{
'name': '[{$gtmProduct->oxarticles__oxtitle->value}]',
'id': '[{$gtmProduct->oxarticles__oxartnum->value}]',
'price': [{$gtmProduct->oxarticles__oxprice->value}],
'brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'variant': '[{if $gtmProduct->oxarticles__oxvarselect->value}][{$gtmProduct->oxarticles__oxvarselect->value}][{/if}]'
[{if $list && $position}],
'list': '[{$list}]',
'position': [{"_"|str_replace:"":$position}]
[{/if}]
}
]
}
});
</script>
<!--
sWidgetType [{$sWidgetType}] | [{$oView->getViewParameter('sWidgetType')}]
sListType [{$sListType}] | [{$oView->getViewParameter('sListType')}]
iIndex [{$iIndex}] | [{$oView->getIndex()}]
listId [{$listId}] | [{$oView->getViewParameter('listId')}]
testid [{$testid}] | [{$oView->getViewParameter('testid')}]
-->

View File

@ -1,10 +1,13 @@
[{$smarty.block.parent}]
[{*$gtmProduct|get_class_methods|dumpvar*}]
[{assign var="d3ProductObject" value=$oView->getProduct()}]
[{assign var="d3PriceObject" value=$d3ProductObject->getPrice()}]
[{capture assign=d3_ga4_add_to_cart}]
[{block name="d3_ga4_add_to_basket"}]
$("#toBasket").click(function(event) {
[{*** Debug cases ***}]
[{*event.preventDefault();*}]
let iArtQuantity = $("#amountToBasket").val();
@ -15,24 +18,18 @@
'eventLabel': 'add_to_cart',
'ecommerce': {
'currency': "[{$currency->name}]",
'value': iArtQuantity*[{$gtmProduct->getFieldData('oxprice')}],
'value': iArtQuantity*[{$d3PriceObject->getPrice()}],
'items': [
{
'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]',
'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]',
'price': '[{$gtmProduct->getFieldData('oxprice')}]',
'price': [{$d3PriceObject->getPrice()}],
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_variant': '[{if $gtmProduct->getFieldData('oxvarselect')}][{$gtmProduct->getFieldData('oxvarselect')}][{/if}]',
'item_category': itemCategories[0] || 'no category',
'item_category_2':itemCategories[1] || '',
'item_category_3':itemCategories[2] || '',
'item_category_4':itemCategories[3] || '',
[{if false}]
[{* ??? what *}]
'item_list_name': 'Search Results', // If associated with a list selection.
'item_list_id': 'SR123', // If associated with a list selection.
'index': 1, // If associated with a list selection.
[{/if}]
'quantity': iArtQuantity
}
]

View File

@ -13,12 +13,13 @@
'search_term': '[{$searchparamforhtml}]',
'items': [
[{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}]
[{assign var="d3PriceObject" value=$gtmProduct->getPrice()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}]
{
'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]',
'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]',
'price': [{$gtmProduct->oxarticles__oxprice->value|default:'0'}],
'price': [{$d3PriceObject->getPrice()}],
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'quantity': 1

View File

@ -1,3 +1,4 @@
[{$smarty.block.parent}]
[{assign var="gtmProducts" value=$products}]
[{assign var="breadCrumb" value=''}]
@ -15,12 +16,13 @@
'item_list_name': '[{foreach from=$oView->getBreadCrumb() item=sCrum}][{if $sCrum.title }][{$breadCrumb|cat:$sCrum.title|cat:" > "}][{/if}][{/foreach}]',
'items': [
[{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}]
[{assign var="d3PriceObject" value=$gtmProduct->getPrice()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}]
{
'item_id': '[{$gtmProduct->getFieldData("oxartnum")}]',
'item_name': '[{$gtmProduct->getFieldData("oxtitle")}]',
'price': [{$gtmProduct->oxarticles__oxprice->value|default:'0'}],
'price': [{$d3PriceObject->getPrice()}],
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'quantity': 1

View File

@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.5.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.4.0...1.5.0) - 2023-05-23
### Added
- additional settings to explicitly indicate that consentmanager is used
### Fixed
- unnecessary converting of int to str
- missing PriceObject-bug
### Changed
- genuine code cleanup
## [1.4.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/1.3.1...1.4.0) - 2023-05-02
### Added
- "OXID Cookie Management powered by usercentrics" compatibility

View File

@ -1,19 +1,19 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
* http://www.shopmodule.com
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\GoogleAnalytics4\Modules\Core;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
class ViewConfig extends ViewConfig_parent
@ -33,6 +33,11 @@ class ViewConfig extends ViewConfig_parent
return $this->sContainerId;
}
public function getModuleConsentmanagerSettingSelectValue() :bool
{
return Registry::getConfig()->getConfigParam('d3_gtm_settings_HAS_CONSENTMANAGER') === 'YES';
}
public function getCookieManagerType()
{
if ($this->sCookieManagerType === null)
@ -52,6 +57,11 @@ class ViewConfig extends ViewConfig_parent
}
}
}
if ($this->sCookieManagerType === false and $this->getModuleConsentmanagerSettingSelectValue()){
return "consentmanager";
}
return $this->sCookieManagerType;
}
@ -60,7 +70,8 @@ class ViewConfig extends ViewConfig_parent
*/
public function D3blShowGtmScript()
{
$oConfig = $this->getConfig();
/** @var Config $oConfig */
$oConfig = Registry::getConfig();
// No Cookie Manager in use
if (!$oConfig->getConfigParam('d3_gtm_settings_hasOwnCookieManager')) {
@ -85,7 +96,7 @@ class ViewConfig extends ViewConfig_parent
}
// UserCentrics
if ($this->getCookieManagerType() == "oxps_usercentrics") {
if ($this->getCookieManagerType() === "oxps_usercentrics" or $this->getCookieManagerType() === 'consentmanager') {
// Always needs the script-tags delivered to the DOM.
return true;
}
@ -101,8 +112,9 @@ class ViewConfig extends ViewConfig_parent
*/
public function getGtmScriptAttributes()
{
$oConfig = Registry::getConfig();
if ($this->getCookieManagerType() == "oxps_usercentrics") {
$oConfig = $this->getConfig();
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
if ($sCookieId) {
@ -110,6 +122,19 @@ class ViewConfig extends ViewConfig_parent
}
}
if ($this->getCookieManagerType() == "consentmanager") {
$sCookieId = $oConfig->getConfigParam('d3_gtm_settings_cookieName');
if ($sCookieId) {
return 'async
type="text/plain"
data-cmp-src="https://www.googletagmanager.com/gtm.js?id='.$this->getGtmContainerId().'"
class="cmplazyload"
data-cmp-vendor="s905"
';
}
}
return "";
}
@ -132,7 +157,6 @@ class ViewConfig extends ViewConfig_parent
$oConfig = Registry::getConfig();
$oView = $oConfig->getTopActiveView();
/** @var FrontendController $oShop */
$oUser = $oConfig->getUser();
$cl = $this->getTopActiveClassName();

View File

@ -17,7 +17,7 @@ $aModule = [
Die Entwicklung basiert auf einem Fork von Marat Bedoev - <a href='https://github.com/vanilla-thunder/oxid-module-gtm'>Github-Link</a>
",
'thumbnail' => 'thumbnail.png',
'version' => '1.4.0',
'version' => '1.5.0',
'author' => 'Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
@ -43,17 +43,11 @@ $aModule = [
'block' => 'theme_svg_icons',
'file' => '/Application/views/blocks/_gtm_nojs.tpl'
],
// widget_product_list
[
'template' => 'widget/product/list.tpl',
'block' => 'widget_product_list',
'file' => '/Application/views/blocks/widget_product_list.tpl'
],
// details
[
'template' => 'page/details/inc/productmain.tpl',
'block' => 'details_productmain_title',
'file' => '/Application/views/blocks/detail.tpl',
'file' => '/Application/views/blocks/view_item.tpl',
'position' => 150
],
// checkout
@ -71,7 +65,7 @@ $aModule = [
// view_item_list
[
'template' => 'widget/product/list.tpl',
'block' => 'd3Ga4_view_item_list',
'block' => 'widget_product_list',
'file' => '/Application/views/ga4/view_item_list.tpl',
'position' => 150
],
@ -126,5 +120,12 @@ $aModule = [
'value' => 'example',
'position' => 999
],
[
'group' => 'd3_gtm_settings_cookiemanager',
'name' => 'd3_gtm_settings_HAS_CONSENTMANAGER',
'type' => 'select',
'value' => 'none',
'constraints' => 'NO|YES',
],
]
];