Merge remote-tracking branch 'remotes/origin/rel_1.x' into dev_1.x_OXID_6.3

This commit is contained in:
MaxBUhe 2023-01-20 11:11:17 +01:00
commit 5200232a32
26 changed files with 725 additions and 578 deletions

13
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP73Migration' => true,
'@PSR12' => true
])
->setFinder($finder)
;

View File

@ -1,5 +0,0 @@
<?php
namespace VanillaThunder\GoogleTagManager\Application\Extend;
class ViewConfig_parent extends \OxidEsales\Eshop\Core\ViewConfig {};

View File

@ -17,15 +17,30 @@ $style = '<style type="text/css">
.groupExp a.rc b {font-size:medium;color:#ff3600;}
.groupExp dt .txt,
.groupExp dt .select,
.groupExp dt .txtfield {width:250px !important; margin: 2px !important; padding: 1px 4px !important; border: 1px solid #ccc !important; }
.groupExp dt .txtfield {width:250px !important; margin: 2px !important; padding: 1px 4px !important; border: 1px solid #ccc !important; }
.groupExp dt textarea.txtfield { min-height: 125px;}
.groupExp dl { display:block !important;}
input.confinput {position:fixed;top:20px;right:70px;background:#008B2D;padding:10px 25px;color:white;border:1px solid black;cursor:pointer;font-size:125%;}
input.confinput:hover {outline:3px solid #ff3600;}
</style>';
$aLang = [
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_vt_gtm_settings' => $style . 'Einstellungen',
'charset' => 'UTF-8',
'SHOP_MODULE_vt_gtm_sContainerID' => 'Container ID',
'SHOP_MODULE_vt_gtm_promotionlistids' => 'Promotion Produktlisten IDs <div>Weitere Infos zu dieser Einstellung: <b><u><a href="https://github.com/vanilla-thunder/oxid-module-gtm/wiki/Promotion-Produktlisten" target="_blank">Modui-Wiki</a></u></b></div>',
'SHOP_MODULE_GROUP_vt_gtm_settings' => 'Einstellungen',
'SHOP_MODULE_vt_gtm_blGA4enab' => 'GA4 Aktivieren',
'SHOP_MODULE_vt_gtm_blUAenabled' => 'UA Aktivieren',
'SHOP_MODULE_vt_gtm_blEnableDebug' => 'Debug-Modus aktivieren',
// for cookie manager settings
'SHOP_MODULE_GROUP_vt_gtm_settings_cookiemanager' => 'Cookie Manager Einstellungen',
'SHOP_MODULE_vt_gtm_settings_hasOwnCookieManager' => 'Eigenen Cookie Manager nutzen?
<strong style="color: red">Hinweis (Fragezeichen) lesen!</strong>',
'HELP_SHOP_MODULE_vt_gtm_settings_hasOwnCookieManager' => 'Stellen Sie sicher, dass Sie ein Modul installiert haben,
dass die Methode "blAcceptedCookie" implementiert.<br> Sollten Sie sich nicht sicher sein kontaktieren Sie Ihren
technischen Ansprechpartner.<br><br>
<strong>Wichtig!</strong> Das Aktivieren dieser Checkbox kann <u>ohne dem nötigen technischen Wissen</u> den Shop-Ablauf im Frontend stören!<hr>
Die Checkbox muss nicht aktiviert werden, sofern die Cookies beispielsweise direkt via Google Cookie-Banner integriert werden.
Bei Fragen <u>kontaktieren Sie bitte</u> auch hier einen entsprechenden technischen Ansprechpartner.',
'SHOP_MODULE_vt_gtm_settings_cookieName' => 'Cookie-Name',
];

View File

@ -1,25 +1,61 @@
[{if $oViewConf->getGtmContainerId()}][{strip}]
<!-- Google Tag Manager -->
<script>
var dataLayer = [{$oViewConf->getGtmDataLayer()}] || [];
(function (w, d, s, l, i) {
[{assign var="d3VtConfigObject" value=$oViewConf->getConfig()}]
[{if $d3VtConfigObject->getConfigParam('vt_gtm_settings_hasOwnCookieManager')}]
[{if $oViewConf->blAcceptedCookie($d3VtConfigObject->getConfigParam('vt_gtm_settings_cookieName'))}]
[{if $oViewConf->getGtmContainerId()}][{strip}]
<!-- Google Tag Manager -->
<script>
var dataLayer = [{$oViewConf->getGtmDataLayer()}] || [];
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '[{$oViewConf->getGtmContainerId()}]');
})(window, document, 'script', 'dataLayer', '[{$oViewConf->getGtmContainerId()}]');
</script>
<!-- End Google Tag Manager -->
[{$oViewConf->triggerGA4events()}]
[{if $oViewConf->getTopActionClassName() === "alist" }]
[{* include file="ga4_view_item_list.tpl" gtmCategory=$oView->getActiveCategory() gtmProducts=$oView->getArticleList() listtype=$oView->getListType() *}]
[{elseif $oViewConf->getTopActionClassName() === "details" }]
[{* include file="ga4_view_item.tpl" gtmProduct=$oView->getProduct() *}]
[{elseif $oViewConf->getTopActionClassName() === "search" }]
[{elseif $oViewConf->getTopActionClassName() === "basket" }]
[{/if}]
[{/strip}][{/if}]
[{else}]
<script>
var dataLayer = [{$oViewConf->getGtmDataLayer()}] || [];
</script>
[{/if}]
[{else}]
[{if $oViewConf->getGtmContainerId()}][{strip}]
<!-- Google Tag Manager -->
<script>
var dataLayer = [{$oViewConf->getGtmDataLayer()}] || [];
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '[{$oViewConf->getGtmContainerId()}]');
</script>
<!-- End Google Tag Manager -->
[{$oViewConf->triggerGA4events()}]
[{if $oViewConf->getTopActionClassName() === "alist" }]
[{* include file="ga4_view_item_list.tpl" gtmCategory=$oView->getActiveCategory() gtmProducts=$oView->getArticleList() listtype=$oView->getListType() *}]
[{* include file="ga4_view_item_list.tpl" gtmCategory=$oView->getActiveCategory() gtmProducts=$oView->getArticleList() listtype=$oView->getListType() *}]
[{elseif $oViewConf->getTopActionClassName() === "details" }]
[{* include file="ga4_view_item.tpl" gtmProduct=$oView->getProduct() *}]
[{* include file="ga4_view_item.tpl" gtmProduct=$oView->getProduct() *}]
[{elseif $oViewConf->getTopActionClassName() === "search" }]
[{elseif $oViewConf->getTopActionClassName() === "basket" }]
[{/if}]
[{/strip}][{/if}]
[{/strip}][{/if}]
[{/if}]
[{$smarty.block.parent}]

View File

@ -1,57 +1,31 @@
[{strip}]
[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'ee.checkout',
'eventLabel':'Checkout Step 1',
'ecommerce': {
'checkout': {
'actionField': {'step': 1},
'products': [
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
[{assign var='_price' value=$basketitem->getUnitPrice()}]
{
'id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
'name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
'variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
'price': [{$_price->getPrice()}],
'quantity':[{$basketitem->getAmount()}],
'position':[{$smarty.foreach.gtmCartContents.index}]
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]
[{/foreach}]
]
}
}
});
[{*
var gtmCartContents = {[{foreach key=basketindex from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents}]
'[{$basketindex}]':{ 'id':'[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]' }[{if !$smarty.foreach.gtmCartContents.last}],[{/if}][{/foreach}]
};
[{$smarty.block.parent}]
[{capture name='removeFromBasket'}]
$('#basketRemove').on('click', function() {
var _checked = [],
_products = [];
[{*$oxcmp_basket|get_class_methods|dumpvar*}]
$('input:checkbox:checked[name^="aproducts"][name*="remove"]').each(function() { _checked.push($(this).attr('name').replace('aproducts[','').replace('][remove]','')); });
if(_checked.length == 0) return;
_checked.forEach(function(_oxid) { _products.push({ 'id':gtmCartContents[_oxid].id}) });
dataLayer.push({
'event':'ee.removeFromCart',
'ecommerce': {
'currencyCode': '[{$currency->name}]',
'remove': {
'products': _products
}
}
});
});
[{/capture }]
[{oxscript add=$smarty.capture.removeFromBasket}]
*}]
</script>
[{/strip}]
[{$smarty.block.parent}]
[{assign var='gtmCartArticles' value=$oView->getBasketArticles()}]
[{strip}][{capture assign=d3_ga4_view_cart}]
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'view_cart',
'eventLabel':'Checkout Step 1',
'ecommerce': {
'actionField': "step: 1",
'currency': "[{$currency->name}]",
'value': [{$oxcmp_basket->getBruttoSum()}],
'items': [
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
[{assign var='_price' value=$basketitem->getUnitPrice()}]
{
'item_id': '[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
'item_name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
'item_variant': '[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
'price': [{$_price->getPrice()}],
'quantity':[{$basketitem->getAmount()}],
'position':[{$smarty.foreach.gtmCartContents.index}]
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]
[{/foreach}]
]
}
});
[{/capture}][{/strip}]
[{oxscript add=$d3_ga4_view_cart}]

View File

@ -1,3 +1,5 @@
[{$smarty.block.parent}]
[{strip}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
@ -5,33 +7,29 @@
[{assign var="_gtmArticles" value=$_gtmOrder->getOrderArticles()}]
dataLayer.push({
'event': 'ee.transaction',
'event': 'purchase',
'eventLabel':'Checkout Step 5',
'ecommerce': {
'purchase': {
'actionField': {
'id':'[{$_gtmOrder->oxorder__oxordernr->value}]',
'affiliation':'[{$oxcmp_shop->oxshops__oxname->value}]',
'revenue':'[{$_gtmOrder->oxorder__oxtotalordersum->value}]',
'tax':'[{math equation="x+y" x=$_gtmOrder->oxorder__oxartvatprice1->value y=$_gtmOrder->oxorder__oxartvatprice2->value }]',
'shipping':'[{$_gtmOrder->oxorder__oxdelcost->value}]',
'currency': "[{$_gtmOrder->getFieldData('oxcurrency')}]"
},
'products':[
[{foreach from=$_gtmArticles item="_gtmArticle" name="gtmArticles"}]
{
'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}],
'position':[{$smarty.foreach.gtmArticles.iteration}]
}[{if !$smarty.foreach.gtmArticles.last}],[{/if}]
[{/foreach}]
]
}
'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}]',
'currency': '[{$_gtmOrder->getFieldData('oxcurrency')}]',
'items':
[
[{foreach from=$_gtmArticles item="_gtmArticle" name="gtmArticles"}]
{
'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}],
'position': [{$smarty.foreach.gtmArticles.iteration}]
}[{if !$smarty.foreach.gtmArticles.last}],[{/if}]
[{/foreach}]
]
}
});
})
</script>
[{/strip}]
[{$smarty.block.parent}]

View File

@ -2,26 +2,24 @@
[{assign var="gtmProduct" value=$oView->getProduct()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{strip}][{/strip}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'ee.detail',
'event': 'view_item',
'eventLabel':'Product View',
'ecommerce': {
'currencyCode': '[{$currency->name}]',
'detail': {
'products': [
{
'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}]'
}
]
}
'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

@ -1,41 +1,58 @@
[{strip}]
[{$gtmProduct|@var_dump}]
[{* variable $gtmProduct is passed from parent tempalte *}]
[{*
[{assign var="gtmCurrency" value=$oView->getActCurrency()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
<script type="text/javascript">
[{$smarty.block.parent}]
var itemCategories = '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]no category[{/if}]'.split('/');
//console.log(itemCategories);
var _gtmProduct = {
'item_name': '[{$gtmProduct->oxarticles__oxtitle->value}]',
'item_id': '[{$gtmProduct->oxarticles__oxartnum->value}]',
'price': '[{$gtmProduct->oxarticles__oxprice->value}]',
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_variant': '[{if $gtmProduct->oxarticles__oxvarselect->value}][{$gtmProduct->oxarticles__oxvarselect->value}][{/if}]',
'item_category': itemCategories[0] || 'no category',
'item_category_2': itemCategories[1] || '',
'item_category_3': itemCategories[2] || '',
'item_category_4': itemCategories[3] || '',
[{*$gtmProduct|get_class_methods|dumpvar*}]
[{capture assign=d3_ga4_add_to_cart}]
$("#toBasket").click(function(event) {
[{*event.preventDefault();*}]
let iArtQuantity = $("#amountToBasket").val();
dataLayer.push({
'isAddToBasket': true,
'event':'add_to_cart',
'eventLabel': 'add_to_cart',
'ecommerce': {
'currency': "[{$currency->name}]",
'value': iArtQuantity*[{$gtmProduct->getFieldData('oxprice')}],
'items': [
{
'item_id': '[{$gtmProduct->getFieldData('oxartnum')}]',
'item_name': '[{$gtmProduct->getFieldData('oxtitle')}]',
'price': '[{$gtmProduct->getFieldData('oxprice')}]',
'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': '1'
};
'quantity': iArtQuantity
}
]
}
});
});
console.log(_gtmProduct);
dataLayer.push({
'event':'ecommerce',
'ga4event': 'add_to_cart',
'ecommerce': {
'items': [ _gtmProduct ]
}
});
[{/capture}]
[{oxscript add=$d3_ga4_add_to_cart}]
[{strip}]
[{* variable $gtmProduct is passed from parent tempalte *}]
[{assign var="gtmCurrency" value=$oView->getActCurrency()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
let itemCategories = '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]no category[{/if}]'.split('/');
</script>
*}]
[{/strip}]

View File

@ -0,0 +1,36 @@
[{strip}]
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
dataLayer.push({
[{assign var="oBasket" value=$order->getBasket()}]
[{assign var="iVat" value=0}]
'event':'purchase',
'ecommerce':{
'purchase':{
'actionField':{
'id': [{$order->getFieldData('oxordernr')}],
'ordernr': [{$order->getFieldData('oxtotalordersum')}],
'tax': [{$order->d3GetSumOrderVat()}],
'shipping': [{$order->getFieldData('oxdelcost')}],
'currency': "[{$order->getFieldData('oxcurrency')}]"
},
'products':[
[{foreach from=$order->getOrderArticles() item=listItem}]
[{assign var="orderArticle" value=$listItem->getArticle()}]
{
'item_id': "[{$listItem->getFieldData('oxartnum')}]",
'item_name': "[{$listItem->getFieldData('oxtitle')}]",
'currency': "[{$order->getFieldData('oxcurrency')}]",
'articleVat': [{$orderArticle->getArticleVat()}],
'price': [{$orderArticle->getBasePrice()}],
'quantity': [{$listItem->getFieldData('oxamount')}]
},
[{/foreach}]
]
}
}
});
</script>
[{/strip}]

View File

@ -0,0 +1,32 @@
[{$smarty.block.parent}]
[{assign var="gtmProducts" value=$oView->getArticleList()}]
[{if $gtmProducts|@count}]
[{strip}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'view_search_result',
'eventLabel':'view_search_result',
'ecommerce': {
'search_term': '[{$searchparamforhtml}]',
'items': [
[{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}]
[{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'}],
'item_brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'item_category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'quantity': 1
}[{if !$smarty.foreach.gtmProducts.last}],[{/if}]
[{/foreach}]
]
}
});
</script>
[{/strip}]
[{/if}]

View File

@ -1,12 +1,18 @@
[{assign var="gtmProducts" value=$products}]
[{assign var="breadCrumb" value=''}]
[{if $gtmProducts|@count}]
[{strip}]
<script>
/* ga4 */
dataLayer.push({ecommerce: null});
dataLayer.push({
'event':'GA4_event',
'event':'view_item_list',
'event_name': 'view_item_list',
'ecommerce': {
'item_list_id': '[{$oView->getCategoryId()}]',
'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="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
@ -23,29 +29,6 @@
]
}
});
/* ua */
dataLayer.push({ecommerce: null});
dataLayer.push({
'event':'UA_event',
'event_name': 'view_item_list',
'ecommerce': {
'currencyCode':'EUR',
'impressions': [
[{foreach from=$gtmProducts name="gtmProducts" item="gtmProduct"}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
[{if !$gtmCategory}][{assign var="gtmCategory" value=$gtmProduct->getCategory()}][{/if}]
{
'id': '[{$gtmProduct->getFieldData("oxartnum")}]',
'name': '[{$gtmProduct->getFieldData("oxtitle")}]',
'price': [{$gtmProduct->oxarticles__oxprice->value|default:'0'}],
'brand': '[{if $gtmManufacturer}][{$gtmManufacturer->oxmanufacturers__oxtitle->value}][{/if}]',
'category': '[{if $gtmCategory}][{$gtmCategory->getLink()|parse_url:5|ltrim:"/"|rtrim:"/"}][{else}]-[{/if}]',
'position': [{$smarty.foreach.gtmProducts.iterator|default:1}]
}[{if !$smarty.foreach.gtmProducts.last}],[{/if}]
[{/foreach}]
]
}
});
</script>
[{/strip}]
[{/if}]

View File

@ -1,29 +0,0 @@
[{strip}]
[{assign var="gtmCategory" value=$gtmProduct->getCategory()}]
[{assign var="gtmManufacturer" value=$gtmProduct->getManufacturer()}]
<script>
/* UA */
dataLayer.push({ecommerce: null});
dataLayer.push({
'event': 'UA_ecommerce',
'event_name': '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}]no category[{/if}]',
'variant': '[{if $gtmProduct->oxarticles__oxvarselect->value}][{$gtmProduct->oxarticles__oxvarselect->value}][{/if}]'
[{if $list && $position}],
'list': '[{$list}]',
'position': [{"_"|str_replace:"":$position}]
[{/if}]
}
]
}
});
</script>
[{/strip}]

View File

@ -1,62 +0,0 @@
[{strip}]
[{assign var="gtmCartArticles" value=$oView->getBasketArticles()}]
<script>
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null});
dataLayer.push({
"event":"enhanced-ecommerce",
"ecommerce": {
"checkout": {
"actionField": {"step":1},
"products": [
[{foreach key=basketindex from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents}]
[{assign var="_price" value=$basketitem->getPrice()}]
{
'id':'[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]',
'name': '[{$gtmCartArticles[$basketindex]->oxarticles__oxtitle->value}]',
'variant':'[{$gtmCartArticles[$basketindex]->oxarticles__oxvarselect->value}]',
'price': [{$_price->getPrice()}],
'quantity':[{$basketitem->getAmount()}],
'position':[{$smarty.foreach.gtmCartContents.index}]
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]
[{/foreach}]
]
}
}
});
var gtmCartContents = {
[{foreach key=basketindex from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents}]
'[{$basketindex}]':{
'id':'[{$gtmCartArticles[$basketindex]->oxarticles__oxartnum->value}]'
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]
[{/foreach}]
};
[{capture name="removeFromBasket"}]
$("#basketRemove").on("click", function() {
var _checked = [],
_products = [];
$("input:checkbox:checked[name^='aproducts'][name*='remove']").each(function() { _checked.push($(this).attr('name').replace("aproducts[","").replace("][remove]","")); });
if(_checked.length == 0) return;
_checked.forEach(function(_oxid) { _products.push({ 'id':gtmCartContents[_oxid].id}) });
dataLayer.push({
'event':'ee.removeFromCart',
'ecommerce': {
'currencyCode': '[{$currency->name}]',
'remove': {
'products': _products
}
}
});
});
/*
*/
[{/capture}]
[{oxscript add=$smarty.capture.removeFromBasket}]
</script>
[{/strip}]
[{$smarty.block.parent}]

View File

@ -1,13 +0,0 @@
<script>
dataLayer.push({
'event':'ee.checkout',
'eventLabel':'Checkout 2',
'ecommerce': {
'checkout': { 'actionField': {
'step': 2,
'option':'[{oxmultilang ident="VT_GTM_EE_LOGINOPTION"|cat:$oView->getLoginOption()}]'
} }
}
});
</script>
[{$smarty.block.parent}]

View File

@ -1,8 +0,0 @@
<script>
dataLayer.push({
'event': 'ee.checkout',
'eventLabel': 'Checkout 3',
'ecommerce': {'checkout': {'actionField': {'step': 3}}}
});
</script>
[{$smarty.block.parent}]

View File

@ -1,8 +0,0 @@
<script>
dataLayer.push({
"event": "ee.checkout",
'eventLabel': 'Checkout 4',
"ecommerce": {"checkout": {"actionField": {"step": 4}}}
});
</script>
[{$smarty.block.parent}]

View File

@ -1,44 +0,0 @@
<script>
[{*
dataLayer.push({
'event': 'ee.checkout',
'eventLabel':'Checkout 5',
'ecommerce': {'checkout': {'actionField': {'step': 5}}}
});
*}]
[{assign var="_gtmOrder" value=$oView->getOrder()}]
[{assign var="_gtmBasket" value=$_gtmOrder->getBasket()}]
[{assign var="_gtmArticles" value=$_gtmOrder->getOrderArticles()}]
dataLayer.push({
'event': 'ee.transaction',
'eventLabel':'[{oxmultilang ident="ORDER_COMPLETED"}]',
'ecommerce': {
'purchase': {
'actionField': {
'id':'[{$_gtmOrder->oxorder__oxordernr->value}]',
'affiliation':'[{$oxcmp_shop->oxshops__oxname->value}]',
'revenue':'[{$_gtmOrder->oxorder__oxtotalordersum->value}]',
'tax':'[{math equation="x+y" x=$_gtmOrder->oxorder__oxartvatprice1->value y=$_gtmOrder->oxorder__oxartvatprice2->value }]',
'shipping':'[{$_gtmOrder->oxorder__oxdelcost->value}]'
/*'coupon':'CANO25' //if a coupon code was used for this order*/
},
'products':[
[{foreach key="_index" from=$_gtmBasket->getContents() item="_gtmBasketitem" name="gtmTransactionProducts"}]
[{assign var="_price" value=$_gtmBasketitem->getPrice()}]
{
'id':'[{$_gtmArticles[$_index]->oxarticles__oxartnum->value}]',
'name': '[{$_gtmArticles[$_index]->oxarticles__oxtitle->value}]',
'variant':'[{$_gtmArticles[$_index]->oxarticles__oxvarselect->value}]',
'price': [{$_price->getPrice()}],
'item_price': [{$_price->getPrice()}],
'quantity':[{$_gtmBasketitem->getAmount()}],
'position':[{$smarty.foreach.gtmTransactionProducts.iteration}]
}[{if !$smarty.foreach.gtmTransactionProducts.last}],[{/if}]
[{/foreach}]
]
}
}
});
</script>
[{$smarty.block.parent}]

30
CHANGELOG.md Normal file
View File

@ -0,0 +1,30 @@
# Changelog
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).
## [Unreleased](https://git.d3data.de/D3Public/MyModule/compare/1.1.0.0...rel_1.x)
## [1.1.0.0](https://git.d3data.de/D3Public/MyModule/compare/1.0.0.0...1.1.0.0) - 2022-07-26
### Added
- another feature
### Changed
- changed old code
### Deprecated
- ...
### Removed
- ...
### Fixed
- ...
### Security
- ...
## [1.0.0.0](https://git.d3data.de/D3Public/MyModule/releases/tag/1.0.0.0) - 2022-07-25
### Added
- implemented features

18
IntelliSenseHelper.php Normal file
View File

@ -0,0 +1,18 @@
<?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
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\GoogleAnalytics4\Modules\Core{
class ViewConfig_parent extends \OxidEsales\Eshop\Core\ViewConfig{}
}

View File

@ -1,129 +1,123 @@
<?php
/*
* vanilla-thunder/oxid-module-gtm
* Google Tag Manager Integration for OXID eShop v6.2+
*
* This program is free software;
* you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
*/
namespace VanillaThunder\GoogleTagManager\Application\Extend;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
class ViewConfig extends ViewConfig_parent
{
// Google Tag Manager Container ID
private $sContainerId = null;
public function getGtmContainerId()
{
if ($this->sContainerId === null)
{
$this->sContainerId = ContainerFactory::getInstance()
->getContainer()
->get(ModuleSettingBridgeInterface::class)
->get('vt_gtm_sContainerID', 'vt-gtm');
}
return $this->sContainerId;
}
private $blGA4enabled = null;
public function isGA4enabled()
{
if ($this->blGA4enabled === null)
{
$this->sContainerId = ContainerFactory::getInstance()
->getContainer()
->get(ModuleSettingBridgeInterface::class)
->get('vt_gtm_blEnableGA4', 'vt-gtm');
}
return $this->blGA4enabled;
}
public function getGtmDataLayer()
{
if (!$this->getGtmContainerId()) return "[]";
$oConfig = Registry::getConfig();
$oView = $oConfig->getTopActiveView();
/** @var FrontendController $oShop */
//$oShop = oxRegistry::getConfig()->getActiveShop(); /** @var oxShop $oShop */
$oUser = $oConfig->getUser();
$cl = $this->getTopActionClassName();
$aPageTypes = [
"content" => "cms",
"details" => "product",
"alist" => "listing",
"search" => "listing",
"basket" => "checkout",
"user" => "checkout",
"payment" => "checkout",
"order" => "checkout",
"thankyou" => "checkout",
];
$dataLayer = [
'page' => [
'type' => $aPageTypes[$cl] ?? "unknown",
'title' => $oView->getTitle(),
'cl' => $cl,
],
'userid' => ($oUser ? $oUser->getId() : false),
'sessionid' => session_id() ?? false,
//'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown"
];
return json_encode([$dataLayer], JSON_PRETTY_PRINT);
unset($dataLayer["user"]["http"]); // das brauchen wir hier nicht
return json_encode([$dataLayer], JSON_PRETTY_PRINT);
/*
// --- Produktdaten ---
$transactionProducts = [];
foreach($oOrder->getOrderArticles() as $_prod ) $transactionProducts[] = [
'name' => '', // (erforderlich) Produktname String
'sku' => '', // (erforderlich) Produkt-SKU String
'category' => '', // (optional) Produktkategorie String
'price' => '', // (erforderlich) Preis pro Einheit Numerischer Wert
'quantity' => '' // (erforderlich) Anzahl der Artikel Numerischer Wert
];
// --- Transaktionsdaten ---
$dataLayer['transactionId'] = $oOrder->oxorder__oxordernr->value; // (erforderlich) Eindeutige Transaktionskennung String
$dataLayer['transactionAffiliation'] = $oShop->oxshops__oxname->value; // (optional) Partner oder Geschäft String
$dataLayer['transactionTotal'] = $oOrder->oxorder__oxtotalordersum->value; // (erforderlich) Gesamtwert der Transaktion Numerischer Wert
$dataLayer['transactionShipping'] = $oOrder->oxorder__oxdelcost->value; // (optional) Versandkosten für die Transaktion Numerischer Wert
$dataLayer['transactionTax'] = ''; // (optional) Steuerbetrag für die Transaktion Numerischer Wert
$dataLayer['transactionProducts'] = $transactionProducts; // (optional) Liste der bei der Transaktion erworbenen Artikel Array von Produktobjekten
*/
}
public function triggerGA4events()
{
// general events
}
public function isPromotionList($listId)
{
$oConfig = Registry::getConfig();
$aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross'];
}
<?php
/*
* vanilla-thunder/oxid-module-gtm
* Google Tag Manager Integration for OXID eShop v6.2+
*
* This program is free software;
* you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
*/
namespace D3\GoogleAnalytics4\Modules\Core;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
class ViewConfig extends ViewConfig_parent
{
// Google Tag Manager Container ID
private $sContainerId = null;
public function getGtmContainerId()
{
if ($this->sContainerId === null)
{
$this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_sContainerID');
}
return $this->sContainerId;
}
private $blGA4enabled = null;
public function isGA4enabled()
{
if ($this->blGA4enabled === null)
{
$this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_blEnableGA4');
}
return $this->blGA4enabled;
}
public function getGtmDataLayer()
{
if (!$this->getGtmContainerId()) return "[]";
$oConfig = Registry::getConfig();
$oView = $oConfig->getTopActiveView();
/** @var FrontendController $oShop */
//$oShop = oxRegistry::getConfig()->getActiveShop(); /** @var oxShop $oShop */
$oUser = $oConfig->getUser();
$cl = $this->getTopActionClassName();
$aPageTypes = [
"content" => "cms",
"details" => "product",
"alist" => "listing",
"search" => "listing",
"basket" => "checkout",
"user" => "checkout",
"payment" => "checkout",
"order" => "checkout",
"thankyou" => "checkout",
];
$dataLayer = [
'page' => [
'type' => $aPageTypes[$cl] ?? "unknown",
'title' => $oView->getTitle(),
'cl' => $cl,
],
'userid' => ($oUser ? $oUser->getId() : false),
'sessionid' => session_id() ?? false,
//'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown"
];
#return json_encode([$dataLayer], JSON_PRETTY_PRINT);
unset($dataLayer["user"]["http"]); // das brauchen wir hier nicht
return json_encode([$dataLayer], JSON_PRETTY_PRINT);
/*
// --- Produktdaten ---
$transactionProducts = [];
foreach($oOrder->getOrderArticles() as $_prod ) $transactionProducts[] = [
'name' => '', // (erforderlich) Produktname String
'sku' => '', // (erforderlich) Produkt-SKU String
'category' => '', // (optional) Produktkategorie String
'price' => '', // (erforderlich) Preis pro Einheit Numerischer Wert
'quantity' => '' // (erforderlich) Anzahl der Artikel Numerischer Wert
];
// --- Transaktionsdaten ---
$dataLayer['transactionId'] = $oOrder->oxorder__oxordernr->value; // (erforderlich) Eindeutige Transaktionskennung String
$dataLayer['transactionAffiliation'] = $oShop->oxshops__oxname->value; // (optional) Partner oder Geschäft String
$dataLayer['transactionTotal'] = $oOrder->oxorder__oxtotalordersum->value; // (erforderlich) Gesamtwert der Transaktion Numerischer Wert
$dataLayer['transactionShipping'] = $oOrder->oxorder__oxdelcost->value; // (optional) Versandkosten für die Transaktion Numerischer Wert
$dataLayer['transactionTax'] = ''; // (optional) Steuerbetrag für die Transaktion Numerischer Wert
$dataLayer['transactionProducts'] = $transactionProducts; // (optional) Liste der bei der Transaktion erworbenen Artikel Array von Produktobjekten
*/
}
public function triggerGA4events()
{
// general events
}
public function isPromotionList($listId)
{
$oConfig = Registry::getConfig();
$aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross'];
}
}

136
README.md Executable file → Normal file
View File

@ -1,60 +1,96 @@
# [vt] Google Tag Manager
Google Tag Manager integration for OXID eShop v6.2 und höher
module version 0.5.0 ( 2021-12-10 )
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
# ![D3 Logo](https://logos.oxidmodule.com/d3logo_24x24.svg) Google-Analytics 4 für OXID eShop
Dieses Modul bietet die Möglichkeit in Ihrem OXID eShop (6.x) die neue 'Property' Google Analytics 4 (GA4) von Google
zu integrieren.
Hierfür stehen Ihnen verschiedene 'templates' zur verfügung, mit denen Sie bestimmte Events tracken können.
Beispiele dafür sind: view_item, add_to_basket, purchase, ...
Weiterführende Informationen: https://developers.google.com/analytics/devguides/collection/ga4
## Inhaltsverzeichnis
- [Installation](#installation)
- [Verwendung](#verwendung)
- [Changelog](#changelog)
- [Lizenz](#lizenz)
## Installation
* ``composer require vanilla-thunder/oxid-module-gtm --no-update``
* Modul aktivieren und Moduleinstellungen konfigurieren
## Tag Manager konfigurieren:
+ https://support.google.com/tagmanager/answer/9442095
Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer in der [composer.json](composer.json) definierten Version.
## Google Analytics 4 Einrichtung
Bitte tragen Sie den folgenden Abschnitt in die `composer.json` Ihres Projektes ein:
## GA4 Events / Customizing
für alle implementierten GA4 Events existieren Templates unter `source/modules/GoogleTagManager/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4.
Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/GoogleTagManager/Application/views/blocks/`.
```
"extra": {
"oxideshop": {
"blacklist-filter": [
"*.md",
"composer.json",
".php-cs-fixer.php",
"*.xml",
"*.neon"
],
"target-directory": "d3/googleanalytics"
}
```
## Universal Analytics Events
**"EE-Trigger" für Ecomemrce-Tags (Beispiel für Google Tag Manager):**
+ Triggertyp: Benutzerdefiniertes Ereignis
+ Ereignisname: ``ee\..*``
+ Übereinstimmung mit regulärem Ausdruck verwenden
+ Diesen Trigger auslösen bei: Alle benutzerdefinierten Ereignisse
**"EE-Tag" für Google Analytics Enhanced Ecommerce:**
+ Tag-Typ: Google Analytics - Universal Analytics
+ Tracking-Typ: Ereignis
+ Aktion: {{Event}}
+ Label: {{Event Label}}
+ Trigger : EE-Trigger
## Verfügbare Datalayer Variablen
Für die einfachste Übersicht der enthaltenen Daten empfehle ich den Vorschau-Modus vom Google Tag Manager.
Bei jedem Seitenaufruf wird die Datenschicht mit einigen wenigen Infos erstellt, die man zum reinen Erfassen der Seitenaufrufe benötigt:
+ **page.type** - Seitentyp: default / cms / product / listing / checkout (an google analytics angelehnt)
+ **page.title** - Seitentitel (außer Startseite, sie hat keinen Titel. Danke OXID...)
+ **page.cl** - OXID Controller Klasse (start, search, etc)
+ **userid** - oxID vom Benutzer bzw `false` falls nicht eingeloggt
+ **sessionid** - session iD
Alle für Ecommerce Tracking releavanten Daten werden mit speziellen Ecommerce Events in die Datenschicht eingefügt.
Hier ist ein Beispiel für die Einrichtung von Enhanced Ecomemrce Tracking über Google Tag Manager:
Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an.
```bash
php composer require d3/google-analytics4:^1
```
Sofern nötig, bestätigen Sie bitte, dass Sie `package-name` erlauben, Code auszuführen.
### LICENSE AGREEMENT
[vt] google-tag-manager
Copyright (C) 2021 Marat Bedoev
info: info@mb-dev.pro oder so /** @todo: überarbeiten, wenn ich wieder nüchtern bin */
This program is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
## Verwendung
Nach erfolgreicher Installation finden Sie in Ihrem Shop-Admin unter "Erweiterungen > Module"
den Eintrag 'Google Analytics 4'.
Aktivieren Sie dieses Modul, um die Funktionalitäten nutzen zu können.
Navigieren Sie danach zum Reiter 'Einstell.'.
Tragen Sie die nötige sog. 'Container ID' ein. Diese sieht in etwa so aus: 'GTM-W34LLOP'.
Aktivieren Sie GA4 selbst, indem Sie dieses direkt darunter anhaken.
---
Sie nutzen einen eigenen, als Modul im Shop installierten, Cookie-manager? Dann tragen Sie in den Folgeeinstellungen
unter "Cookie Manager Einstellungen", die Cookie-ID des zugehörigen Cookies ein. Und aktivieren Sie diese Weiche,
indem Sie den Haken bei "Eigenen Cookie Manager nutzen?" setzen.
## Changelog
Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen.
## Beitragen
Wenn Sie einen Verbesserungsvorschlag haben, legen Sie einen Fork des Repositories an und erstellen Sie einen Pull Request. Alternativ können Sie einfach ein Issue erstellen. Fügen Sie das Projekt zu Ihren Favoriten hinzu. Vielen Dank.
- Erstellen Sie einen Fork des Projekts
- Erstellen Sie einen Feature Branch (git checkout -b feature/AmazingFeature)
- Fügen Sie Ihre Änderungen hinzu (git commit -m 'Add some AmazingFeature')
- Übertragen Sie den Branch (git push origin feature/AmazingFeature)
- Öffnen Sie einen Pull Request
## Lizenz
(Stand: 06.05.2021)
Vertrieben unter der GPLv3 Lizenz.
```
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben.
```
Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde.
## weitere Lizenzen und Nutzungsbedingungen
...

67
__README.md Normal file
View File

@ -0,0 +1,67 @@
# [D3] Google Tag Manager
Google Tag Manager integration for OXID eShop v6.x
## Installation
* ``composer require vanilla-thunder/oxid-module-gtm --no-update``
* Modul aktivieren und Moduleinstellungen konfigurieren
## Tag Manager konfigurieren:
+ https://support.google.com/tagmanager/answer/9442095
## Google Analytics 4 Einrichtung
## GA4 Events / Customizing
für alle implementierten GA4 Events existieren Templates unter `source/modules/GoogleTagManager/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4.
Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/GoogleTagManager/Application/views/blocks/`.
### aktuell zu beachtende Blöcke
- Suchergebnisse: search_results
- (muss hinzugefügt werden) aList: d3Ga4_view_item_list
- Detailseite: details_productmain_title
- add_to_basket-button: details_productmain_tobasket
- Warenkorb: checkout_basket_main
- Purchase | abgeschlossener Kauf: checkout_thankyou_main
## Universal Analytics Events
**"EE-Trigger" für Ecomemrce-Tags (Beispiel für Google Tag Manager):**
+ Triggertyp: Benutzerdefiniertes Ereignis
+ Ereignisname: ``ee\..*``
+ Übereinstimmung mit regulärem Ausdruck verwenden
+ Diesen Trigger auslösen bei: Alle benutzerdefinierten Ereignisse
**"EE-Tag" für Google Analytics Enhanced Ecommerce:**
+ Tag-Typ: Google Analytics - Universal Analytics
+ Tracking-Typ: Ereignis
+ Aktion: {{Event}}
+ Label: {{Event Label}}
+ Trigger : EE-Trigger
## Verfügbare Datalayer Variablen
Für die einfachste Übersicht der enthaltenen Daten empfehle ich den Vorschau-Modus vom Google Tag Manager.
Bei jedem Seitenaufruf wird die Datenschicht mit einigen wenigen Infos erstellt, die man zum reinen Erfassen der Seitenaufrufe benötigt:
+ **page.type** - Seitentyp: default / cms / product / listing / checkout (an google analytics angelehnt)
+ **page.title** - Seitentitel (außer Startseite, sie hat keinen Titel. Danke OXID...)
+ **page.cl** - OXID Controller Klasse (start, search, etc)
+ **userid** - oxID vom Benutzer bzw `false` falls nicht eingeloggt
+ **sessionid** - session iD
Alle für Ecommerce Tracking releavanten Daten werden mit speziellen Ecommerce Events in die Datenschicht eingefügt.
Hier ist ein Beispiel für die Einrichtung von Enhanced Ecomemrce Tracking über Google Tag Manager:
### LICENSE AGREEMENT
[vt] google-tag-manager
Copyright (C) 2021 Marat Bedoev
info: info@mb-dev.pro oder so /** @todo: überarbeiten, wenn ich wieder nüchtern bin */
This program is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>

View File

@ -1,8 +1,19 @@
{
"name": "vanilla-thunder/oxid-module-gtm",
"description": "Google Tag Manager with new Google Analytics 4 for OXID eShop v6.2+<br/>more about GA4: <a href='https://developers.google.com/tag-manager/ecommerce-ga4' target='_blank'>Ecommerce (GA4) Developer Guide</a>",
"name": "d3/google-analytics4",
"description": "Google Tag Manager with new Google Analytics 4 for OXID eShop v6",
"type": "oxideshop-module",
"homepage": "https://github.com/vanilla-thunder/oxid-module-gtm",
"keywords": [
"oxid",
"modules",
"eShop",
"d3",
"google",
"ga4",
"googleanalytics",
"gtm",
"configuration"
],
"homepage": "https://www.d3data.de",
"license": [
"GPL-3.0"
],
@ -10,21 +21,36 @@
{
"name": "Marat Bedoev",
"email": "hello@mb-dev.pro"
},
{
"name": "D3 Data Development (Inh. Thomas Dartsch)",
"email": "info@shopmodule.com",
"homepage": "https://www.d3data.de"
}
],
"support": {
"email": "support@shopmodule.com"
},
"extra": {
"oxideshop": {
"target-directory": "vt/GoogleTagManager"
"blacklist-filter": [
"*.md",
"composer.json",
".php-cs-fixer.php",
"*.xml",
"*.neon"
],
"target-directory": "d3/googleanalytics4"
}
},
"require": {
"php": ">=7.1",
"oxid-esales/oxideshop-ce": "~v6.5",
"oxid-esales/oxideshop-ce": "v6.0 - 6.3",
"google/apiclient":" ^2.0"
},
"autoload": {
"psr-4": {
"VanillaThunder\\": "../../../source/modules/vt"
"D3\\GoogleAnalytics4\\": "../../../source/modules/d3/googleanalytics4"
}
}
}

View File

@ -1,49 +1,50 @@
<?php
/**
* vanilla-thunder/oxid-module-gtm
* Google Tag Manager Integration for OXID eShop v6.2+
*
* This program is free software;
* you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
**/
use D3\GoogleAnalytics4\Modules\Core\ViewConfig;
use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig;
$sMetadataVersion = '2.1';
$aModule = [
'id' => 'vt-gtm',
'title' => '[vt] Google Tag Manager',
'description' => 'Google Tag Manager Integration for OXID eShop v6.2+',
'id' => 'd3googleanalytics4',
'title' => 'Google Analytics 4',
'description' => "Dieses Modul bietet die Möglichkeit in Ihrem OXID eShop (6.x) die neue 'Property'
Google Analytics 4 (GA4) von Google zu integrieren.<br>
Hierfür stehen Ihnen verschiedene 'templates' zur verfügung,
mit denen Sie bestimmte Events tracken können.<br>
Beispiele dafür sind: view_item, add_to_basket, purchase, ...<br><br>
Die Integration und Verbindung zu Google wird mithilfe des gtag (Google Tag Manager) realisiert.<br><br>
Weiterführende Informationen: https://developers.google.com/analytics/devguides/collection/ga4<br>
<hr>
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' => '0.5.0 ( 2021-07-17 )',
'author' => 'Marat Bedoev',
'email' => openssl_decrypt("Az6pE7kPbtnTzjHlPhPCa4ktJLphZ/w9gKgo5vA//p4=", str_rot13("nrf-128-pop"), str_rot13("gvalzpr")),
'url' => 'https://github.com/vanilla-thunder/oxid-module-gtm',
'version' => '1.0.0.0',
'author' => 'Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
'extend' => [
\OxidEsales\Eshop\Core\ViewConfig::class => VanillaThunder\GoogleTagManager\Application\Extend\ViewConfig::class
OEViewConfig::class => ViewConfig::class
],
'templates' => [
// GA4 events
'ga4_add_payment_info.tpl' => 'vt/GoogleTagManager/Application/views/ga4/add_payment_info.tpl',
'add_shipping_info.tpl' => 'vt/GoogleTagManager/Application/views/ga4/add_shipping_info.tpl',
'ga4_add_to_cart.tpl' => 'vt/GoogleTagManager/Application/views/ga4/add_to_cart.tpl',
'ga4_begin_checkout.tpl' => 'vt/GoogleTagManager/Application/views/ga4/begin_checkout.tpl',
'ga4_generate_lead.tpl' => 'vt/GoogleTagManager/Application/views/ga4/generate_lead.tpl',
'ga4_login.tpl' => 'vt/GoogleTagManager/Application/views/ga4/login.tpl',
'ga4_purchase.tpl' => 'vt/GoogleTagManager/Application/views/ga4/purchase.tpl',
'ga4_remove_from_cart.tpl' => 'vt/GoogleTagManager/Application/views/ga4/remove_from_cart.tpl',
'ga4_search.tpl' => 'vt/GoogleTagManager/Application/views/ga4/search.tpl',
'ga4_select_content.tpl' => 'vt/GoogleTagManager/Application/views/ga4/select_content.tpl',
'ga4_select_item.tpl' => 'vt/GoogleTagManager/Application/views/ga4/select_item.tpl',
'ga4_select_promotion.tpl' => 'vt/GoogleTagManager/Application/views/ga4/select_promotion.tpl',
'ga4_sign_up.tpl' => 'vt/GoogleTagManager/Application/views/ga4/sign_up.tpl',
'ga4_view_cart.tpl' => 'vt/GoogleTagManager/Application/views/ga4/view_cart.tpl',
'ga4_view_item.tpl' => 'vt/GoogleTagManager/Application/views/ga4/view_item.tpl',
'ga4_view_item_list.tpl' => 'vt/GoogleTagManager/Application/views/ga4/view_item_list.tpl',
'ga4_view_promotion.tpl' => 'vt/GoogleTagManager/Application/views/ga4/view_promotion.tpl',
'ga4_add_payment_info.tpl' => 'd3/googleanalytics4/Application/views/ga4/add_payment_info.tpl',
'add_shipping_info.tpl' => 'd3/googleanalytics4/Application/views/ga4/add_shipping_info.tpl',
'ga4_add_to_cart.tpl' => 'd3/googleanalytics4/Application/views/ga4/add_to_cart.tpl',
'ga4_begin_checkout.tpl' => 'd3/googleanalytics4/Application/views/ga4/begin_checkout.tpl',
'ga4_generate_lead.tpl' => 'd3/googleanalytics4/Application/views/ga4/generate_lead.tpl',
'ga4_login.tpl' => 'd3/googleanalytics4/Application/views/ga4/login.tpl',
'ga4_purchase.tpl' => 'd3/googleanalytics4/Application/views/ga4/purchase.tpl',
'ga4_remove_from_cart.tpl' => 'd3/googleanalytics4/Application/views/ga4/remove_from_cart.tpl',
'ga4_search.tpl' => 'd3/googleanalytics4/Application/views/ga4/search.tpl',
'ga4_select_content.tpl' => 'd3/googleanalytics4/Application/views/ga4/select_content.tpl',
'ga4_select_item.tpl' => 'd3/googleanalytics4/Application/views/ga4/select_item.tpl',
'ga4_select_promotion.tpl' => 'd3/googleanalytics4/Application/views/ga4/select_promotion.tpl',
'ga4_sign_up.tpl' => 'd3/googleanalytics4/Application/views/ga4/sign_up.tpl',
'ga4_view_cart.tpl' => 'd3/googleanalytics4/Application/views/ga4/view_cart.tpl',
'ga4_view_item.tpl' => 'd3/googleanalytics4/Application/views/ga4/view_item.tpl',
'ga4_view_item_list.tpl' => 'd3/googleanalytics4/Application/views/ga4/view_item_list.tpl',
'ga4_view_promotion.tpl' => 'd3/googleanalytics4/Application/views/ga4/view_promotion.tpl',
/*
'gtm_ua_impression' => 'vt/GoogleTagManager/Application/views/ua/impression.tpl'
'gtm_view_promotion.tpl' => 'vt/GoogleTagManager/Application/views/view_promotion.tpl',
@ -80,7 +81,8 @@ $aModule = [
[
'template' => 'page/details/inc/productmain.tpl',
'block' => 'details_productmain_title',
'file' => '/Application/views/blocks/detail.tpl'
'file' => '/Application/views/blocks/detail.tpl',
'position' => 150
],
// checkout
[
@ -117,6 +119,25 @@ $aModule = [
'template' => 'page/checkout/thankyou.tpl',
'block' => 'checkout_thankyou_main',
'file' => '/Application/views/blocks/checkout_s5.tpl'
],
// Lists
// view_item_list
[
'template' => 'widget/product/list.tpl',
'block' => 'd3Ga4_view_item_list',
'file' => '/Application/views/ga4/view_item_list.tpl'
],
// view_search_result
[
'template' => 'page/search/search.tpl',
'block' => 'search_results',
'file' => '/Application/views/ga4/search.tpl'
],
// add_to_cart
[
'template' => 'page/details/inc/productmain.tpl',
'block' => 'details_productmain_tobasket',
'file' => '/Application/views/ga4/add_to_cart.tpl'
]
],
'settings' => [
@ -129,39 +150,31 @@ $aModule = [
],
[
'group' => 'vt_gtm_settings',
'name' => 'vt_gtm_blGA4enabled',
'name' => 'vt_gtm_blGA4enab',
'type' => 'bool',
'value' => true,
'position' => 1
],
[
'group' => 'vt_gtm_settings',
'name' => 'vt_gtm_blUAenabled',
'type' => 'bool',
'value' => true,
'position' => 2
],
[
'group' => 'vt_gtm_settings',
'name' => 'vt_gtm_sMpapisecret',
'type' => 'str',
'value' => '',
'position' => 3
],
[
'group' => 'vt_gtm_settings',
'name' => 'vt_gtm_aPromotionlistIDs',
'type' => 'arr',
'value' => [],
'position' => 4
],
[
'group' => 'vt_gtm_settings',
'name' => 'vt_gtm_blEnableDebug',
'type' => 'bool',
'value' => false,
'position' => 999
]
],
[
'group' => 'vt_gtm_settings_cookiemanager',
'name' => 'vt_gtm_settings_hasOwnCookieManager',
'type' => 'bool',
'value' => false,
'position' => 999
],
[
'group' => 'vt_gtm_settings_cookiemanager',
'name' => 'vt_gtm_settings_cookieName',
'type' => 'str',
'value' => 'example',
'position' => 999
],
]
];

10
phpstan.neon Normal file
View File

@ -0,0 +1,10 @@
parameters:
scanFiles:
- IntelliSenseHelper.php
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
- ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php
level: 9
phpVersion: 70100
checkMissingIterableValueType: false
ignoreErrors:
- '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'

20
phpunit.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuite name="myModule">
<directory>./Tests</directory>
</testsuite>
<logging/>
</phpunit>