[Added] new Event "add_payment_info"

- add Payment-Model extension for own small method
- new block extension
- new template for the event-data for GA
- metadata adjustments for it
This commit is contained in:
MaxBuhe01 2024-08-20 19:58:02 +02:00
parent 6bdf788ebf
commit 79994eae69
6 changed files with 162 additions and 67 deletions

View File

@ -0,0 +1,3 @@
[{$smarty.block.parent}]
[{include file="event/add_payment_info.tpl"}]

View File

@ -0,0 +1,53 @@
[{*$oxcmp_basket|get_class_methods|dumpvar*}]
[{assign var="gtmBasketPrice" value=$oxcmp_basket->getPrice()}]
[{assign var="gtmBasketObject" value=$oxcmp_basket}]
[{assign var='gtmCartArticles' value=$gtmBasketObject->getBasketArticles()}]
[{assign var="gtmPaymentObject" value=$oView->getPayment()}]
[{block name="gtm_ga4_add_payment_info_block"}]
[{capture name="gtm_ga4_add_payment_info"}]
[{strip}]
dataLayer.push({"event": null, "eventLabel": null, "ecommerce": null}); /* Clear the previous ecommerce object. */
dataLayer.push({
'event': 'add_payment_info',
'eventLabel':'Checkout - Payment info',
'payment_type':'[{$gtmPaymentObject->gtmGetSelectedPaymentName()}]',
'ecommerce':
{
'actionField': "Payment-Info",
'currency': "[{$currency->name}]",
'value': [{$gtmBasketPrice->getPrice()}],
'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]',
'items':
[
[{foreach from=$oxcmp_basket->getContents() item=basketitem name=gtmCartContents key=basketindex}]
[{assign var="gtmItemPriceObject" value=$basketitem->getPrice()}]
[{assign var="gtmBasketItem" value=$basketitem->getArticle()}]
[{assign var="gtmBasketItemCategory" value=$gtmBasketItem->getCategory()}]
{
'item_id': '[{$gtmCartArticles[$basketindex]->getFieldData('oxartnum')}]',
'item_name': '[{$gtmCartArticles[$basketindex]->getFieldData('oxtitle')}]',
'item_variant': '[{$gtmCartArticles[$basketindex]->getFieldData('oxvarselect')}]',
[{if $gtmBasketItemCategory}]
'item_category': '[{$gtmBasketItemCategory->getSplitCategoryArray(0, true)}]',
'item_category_2': '[{$gtmBasketItemCategory->getSplitCategoryArray(1, true)}]',
'item_category_3': '[{$gtmBasketItemCategory->getSplitCategoryArray(2, true)}]',
'item_category_4': '[{$gtmBasketItemCategory->getSplitCategoryArray(3, true)}]',
'item_list_name': '[{$gtmBasketItemCategory->getSplitCategoryArray()}]',
[{/if}]
'price': [{$gtmItemPriceObject->getPrice()}],
'coupon': '[{foreach from=$oxcmp_basket->getVouchers() item=sVoucher key=key name=Voucher}][{$sVoucher->sVoucherNr}][{if !$smarty.foreach.Voucher.last}], [{/if}][{/foreach}]',
'quantity': [{$basketitem->getAmount()}],
'position': [{$smarty.foreach.gtmCartContents.index}]
}[{if !$smarty.foreach.gtmCartContents.last}],[{/if}]
[{/foreach}]
]
}[{if $oViewConf->isDebugModeOn()}],
'debug_mode': 'true'
[{/if}]
});
[{/strip}]
[{/capture}]
[{oxscript add=$smarty.capture.gtm_ga4_add_payment_info}]
[{/block}]

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.20.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.19.0...2.20.0) - 2024-08-20 ## [2.20.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.19.0...2.20.0) - 2024-08-20
### Added ### Added
- new event "begin_checkout" - new event "begin_checkout"
- new event "add_payment_info"
## [2.19.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.18.2...2.19.0) - 2024-08-10 ## [2.19.0](https://git.d3data.de/D3Public/GoogleAnalytics4/compare/2.18.2...2.19.0) - 2024-08-10
### Fixed ### Fixed

View File

@ -18,9 +18,14 @@ namespace D3\GoogleAnalytics4\Modules\Core{
} }
namespace D3\GoogleAnalytics4\Modules\Application\Model{ namespace D3\GoogleAnalytics4\Modules\Application\Model{
use OxidEsales\Eshop\Application\Model\Payment;
class Category_parent extends \OxidEsales\Eshop\Application\Model\Category {} class Category_parent extends \OxidEsales\Eshop\Application\Model\Category {}
class Basket_parent extends \OxidEsales\Eshop\Application\Model\Basket {} class Basket_parent extends \OxidEsales\Eshop\Application\Model\Basket {}
class Manufacturer_parent extends \OxidEsales\Eshop\Application\Model\Manufacturer {} class Manufacturer_parent extends \OxidEsales\Eshop\Application\Model\Manufacturer {}
class gtmPayment_parent extends Payment {}
} }
namespace D3\GoogleAnalytics4\Modules\Application\Controller{ namespace D3\GoogleAnalytics4\Modules\Application\Controller{

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace D3\GoogleAnalytics4\Modules\Application\Model;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Core\Registry;
class gtmPayment extends gtmPayment_parent
{
/**
* @return string
*/
public function gtmGetSelectedPaymentName() :string
{
return $this->getFieldData('oxpayments__oxdesc')?: 'No payment name available';
}
}

View File

@ -16,6 +16,7 @@ use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmStartController;
use D3\GoogleAnalytics4\Modules\Application\Controller\ThankYouController; use D3\GoogleAnalytics4\Modules\Application\Controller\ThankYouController;
use D3\GoogleAnalytics4\Modules\Application\Model\Basket as Basket; use D3\GoogleAnalytics4\Modules\Application\Model\Basket as Basket;
use D3\GoogleAnalytics4\Modules\Application\Model\Category as Category; use D3\GoogleAnalytics4\Modules\Application\Model\Category as Category;
use D3\GoogleAnalytics4\Modules\Application\Model\gtmPayment as gtmPayment;
use D3\GoogleAnalytics4\Modules\Application\Model\Manufacturer as Manufacturer; use D3\GoogleAnalytics4\Modules\Application\Model\Manufacturer as Manufacturer;
use D3\GoogleAnalytics4\Modules\Core\ViewConfig; use D3\GoogleAnalytics4\Modules\Core\ViewConfig;
use OxidEsales\Eshop\Application\Component\BasketComponent as OEBasketComponent; use OxidEsales\Eshop\Application\Component\BasketComponent as OEBasketComponent;
@ -33,12 +34,13 @@ use OxidEsales\Eshop\Application\Controller\ThankYouController as OEThankYouCont
use OxidEsales\Eshop\Application\Model\Basket as OEBasket; use OxidEsales\Eshop\Application\Model\Basket as OEBasket;
use OxidEsales\Eshop\Application\Model\Category as OECategory; use OxidEsales\Eshop\Application\Model\Category as OECategory;
use OxidEsales\Eshop\Application\Model\Manufacturer as OEManufacturer; use OxidEsales\Eshop\Application\Model\Manufacturer as OEManufacturer;
use OxidEsales\Eshop\Application\Model\Payment as OEPayment;
use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig; use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig;
$sMetadataVersion = '2.1'; $sMetadataVersion = '2.1';
$aModule = [ $aModule = [
'id' => Constants::OXID_MODULE_ID, 'id' => Constants::OXID_MODULE_ID,
'title' => 'Google Analytics 4', 'title' => 'Google Analytics 4',
'description' => "Dieses Modul bietet die Möglichkeit in Ihrem OXID eShop (6.x) die neue 'Property' '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> Google Analytics 4 (GA4) von Google zu integrieren.<br>
Hierfür stehen Ihnen verschiedene 'templates' zur verfügung, Hierfür stehen Ihnen verschiedene 'templates' zur verfügung,
@ -49,144 +51,155 @@ $aModule = [
<hr> <hr>
Die Entwicklung basiert auf einem Fork von Marat Bedoev - <a href='https://github.com/vanilla-thunder/oxid-module-gtm'>Github-Link</a> 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', 'thumbnail' => 'thumbnail.png',
'version' => 'DEV-2.20.0', 'version' => 'DEV-2.20.0',
'author' => 'Data Development (Inh.: Thomas Dartsch)', 'author' => 'Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com', 'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/', 'url' => 'https://www.oxidmodule.com/',
'controllers' => [ 'controllers' => [
'd3googleanalytics4_main' => GA4AdminUserInterfaceMainController::class 'd3googleanalytics4_main' => GA4AdminUserInterfaceMainController::class
], ],
'extend' => [ 'extend' => [
// Core // Core
OEViewConfig::class => ViewConfig::class, OEViewConfig::class => ViewConfig::class,
// Model // Model
OECategory::class => Category::class, OECategory::class => Category::class,
OEBasket::class => Basket::class, OEBasket::class => Basket::class,
OEManufacturer::class => Manufacturer::class, OEManufacturer::class => Manufacturer::class,
OEPayment::class => gtmPayment::class,
// Controller // Controller
OEBasketController::class => BasketController::class, OEBasketController::class => BasketController::class,
OEThankYouController::class => ThankYouController::class, OEThankYouController::class => ThankYouController::class,
OEArticleListController::class => ArticleListController_AddToCartHelpMethods::class, OEArticleListController::class => ArticleListController_AddToCartHelpMethods::class,
OEArticleDetailsController::class => ArticleDetailsController::class, OEArticleDetailsController::class => ArticleDetailsController::class,
OEAccountNoticeListController::class => d3GtmAccountNoticeListController::class, OEAccountNoticeListController::class => d3GtmAccountNoticeListController::class,
OEAccountRecommlistController::class => d3GtmAccountRecommlistController::class, OEAccountRecommlistController::class => d3GtmAccountRecommlistController::class,
OEAccountWishlistController::class => d3GtmAccountWishlistController::class, OEAccountWishlistController::class => d3GtmAccountWishlistController::class,
OEStartController::class => d3GtmStartController::class, OEStartController::class => d3GtmStartController::class,
OESearchController::class => d3GtmSearchController::class, OESearchController::class => d3GtmSearchController::class,
OEManufacturerListController::class => d3GtmManufacturerListController::class, OEManufacturerListController::class => d3GtmManufacturerListController::class,
// Component // Component
OEArticleDetails::class => d3GtmWidgetArticleDetails::class, OEArticleDetails::class => d3GtmWidgetArticleDetails::class,
OEBasketComponent::class => d3GtmBasketComponentExtension::class, OEBasketComponent::class => d3GtmBasketComponentExtension::class,
], ],
'templates' => [ 'templates' => [
// Event files that store the GA4 Event-Information // Event files that store the GA4 Event-Information
'event/add_to_cart.tpl' => 'd3/googleanalytics4/Application/views/event/add_to_cart.tpl', 'event/add_to_cart.tpl' => 'd3/googleanalytics4/Application/views/event/add_to_cart.tpl',
'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl', 'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl',
'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl', 'event/view_item.tpl' => 'd3/googleanalytics4/Application/views/event/view_item.tpl',
'event/begin_checkout.tpl' => 'd3/googleanalytics4/Application/views/event/begin_checkout.tpl', 'event/begin_checkout.tpl' => 'd3/googleanalytics4/Application/views/event/begin_checkout.tpl',
'event/purchase.tpl' => 'd3/googleanalytics4/Application/views/event/purchase.tpl', 'event/add_payment_info.tpl' => 'd3/googleanalytics4/Application/views/event/add_payment_info.tpl',
'event/view_item_list.tpl' => 'd3/googleanalytics4/Application/views/event/view_item_list.tpl', 'event/purchase.tpl' => 'd3/googleanalytics4/Application/views/event/purchase.tpl',
'event/view_search_result.tpl' => 'd3/googleanalytics4/Application/views/event/view_search_result.tpl', 'event/view_item_list.tpl' => 'd3/googleanalytics4/Application/views/event/view_item_list.tpl',
'event/remove_from_cart.tpl' => 'd3/googleanalytics4/Application/views/event/remove_from_cart.tpl', 'event/view_search_result.tpl' => 'd3/googleanalytics4/Application/views/event/view_search_result.tpl',
'event/remove_from_cart.tpl' => 'd3/googleanalytics4/Application/views/event/remove_from_cart.tpl',
// complete overwritten file of OXID-Originals // complete overwritten file of OXID-Originals
// the path of the template-name is the original path to the file in OXID-context from tpl/-> // the path of the template-name is the original path to the file in OXID-context from tpl/->
'page/account/d3gtmnoticelist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmnoticelist.tpl', 'page/account/d3gtmnoticelist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmnoticelist.tpl',
'page/account/d3gtmrecommendationlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl', 'page/account/d3gtmrecommendationlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmrecommendationlist.tpl',
'page/account/d3gtmwishlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmwishlist.tpl', 'page/account/d3gtmwishlist.tpl' => 'd3/googleanalytics4/Application/views/tpl/page/account/d3gtmwishlist.tpl',
// Admin Templates // Admin Templates
'ga4/admin/d3ga4uimain.tpl' => 'd3/googleanalytics4/Application/views/admin/tpl/d3googleanalytics4_main.tpl', 'ga4/admin/d3ga4uimain.tpl' => 'd3/googleanalytics4/Application/views/admin/tpl/d3googleanalytics4_main.tpl',
'ga4/admin/d3ga4uiheaditem.tpl' => 'd3/googleanalytics4/Application/views/admin/tpl/d3googleanalytics4_headitem.tpl', 'ga4/admin/d3ga4uiheaditem.tpl' => 'd3/googleanalytics4/Application/views/admin/tpl/d3googleanalytics4_headitem.tpl',
], ],
'blocks' => [ 'blocks' => [
// tag manager js // tag manager js
[ [
'template' => 'layout/base.tpl', 'template' => 'layout/base.tpl',
'block' => 'head_meta_robots', 'block' => 'head_meta_robots',
'file' => '/Application/views/blocks/_gtm_js.tpl', 'file' => '/Application/views/blocks/_gtm_js.tpl',
'position' => 150 'position' => 150
], ],
// tag manager nojs // tag manager nojs
[ [
'template' => 'layout/base.tpl', 'template' => 'layout/base.tpl',
'block' => 'theme_svg_icons', 'block' => 'theme_svg_icons',
'file' => '/Application/views/blocks/_gtm_nojs.tpl' 'file' => '/Application/views/blocks/_gtm_nojs.tpl'
], ],
// details // details
[ [
'template' => 'page/details/inc/productmain.tpl', 'template' => 'page/details/inc/productmain.tpl',
'block' => 'details_productmain_title', 'block' => 'details_productmain_title',
'file' => '/Application/views/blocks/view_item.tpl', 'file' => '/Application/views/blocks/view_item.tpl',
'position' => 150 'position' => 150
], ],
// View Cart // View Cart
[ [
'template' => 'page/checkout/basket.tpl', 'template' => 'page/checkout/basket.tpl',
'block' => 'checkout_basket_main', 'block' => 'checkout_basket_main',
'file' => '/Application/views/blocks/view_cart.tpl' 'file' => '/Application/views/blocks/view_cart.tpl'
], ],
// add_to_cart // add_to_cart
[ [
'template' => 'page/details/inc/productmain.tpl', 'template' => 'page/details/inc/productmain.tpl',
'block' => 'details_productmain_tobasket', 'block' => 'details_productmain_tobasket',
'file' => '/Application/views/blocks/details_productmain_tobasket.tpl', 'file' => '/Application/views/blocks/details_productmain_tobasket.tpl',
'position' => 150 'position' => 150
], ],
// remove_from_cart // remove_from_cart
[ [
'template' => 'page/checkout/basket.tpl', 'template' => 'page/checkout/basket.tpl',
'block' => 'checkout_basket_main', 'block' => 'checkout_basket_main',
'file' => '/Application/views/blocks/remove_from_cart.tpl', 'file' => '/Application/views/blocks/remove_from_cart.tpl',
'position' => 150 'position' => 150
], ],
[ [
'template' => 'page/checkout/thankyou.tpl', 'template' => 'page/checkout/thankyou.tpl',
'block' => 'checkout_thankyou_main', 'block' => 'checkout_thankyou_main',
'file' => '/Application/views/blocks/purchase.tpl' 'file' => '/Application/views/blocks/purchase.tpl'
], ],
// Lists // Lists
// view_item_list // view_item_list
[ [
'template' => 'page/list/list.tpl', 'template' => 'page/list/list.tpl',
'block' => 'page_list_productlist', 'block' => 'page_list_productlist',
'file' => '/Application/views/blocks/view_item_list.tpl', 'file' => '/Application/views/blocks/view_item_list.tpl',
'position' => 150 'position' => 150
], ],
// view_search_result // view_search_result
[ [
'template' => 'page/search/search.tpl', 'template' => 'page/search/search.tpl',
'block' => 'search_results', 'block' => 'search_results',
'file' => '/Application/views/blocks/view_search_result.tpl', 'file' => '/Application/views/blocks/view_search_result.tpl',
'position' => 150 'position' => 150
], ],
[ [
'template' => 'page/list/list.tpl', 'template' => 'page/list/list.tpl',
'block' => 'page_list_listbody', 'block' => 'page_list_listbody',
'file' => '/Application/views/blocks/page_list_listbody.tpl', 'file' => '/Application/views/blocks/page_list_listbody.tpl',
'position' => 150 'position' => 150
], ],
[ [
'template' => 'page/shop/start.tpl', 'template' => 'page/shop/start.tpl',
'block' => 'start_welcome_text', 'block' => 'start_welcome_text',
'file' => '/Application/views/blocks/start_welcome_text.tpl', 'file' => '/Application/views/blocks/start_welcome_text.tpl',
'position' => 150 'position' => 150
], ],
// Checkout process // Checkout process
// Begin CHeckout // Begin CHeckout
[ [
'template' => 'page/checkout/user.tpl', 'template' => 'page/checkout/user.tpl',
'block' => 'checkout_user_main', 'block' => 'checkout_user_main',
'file' => '/Application/views/blocks/begin_checkout.tpl', 'file' => '/Application/views/blocks/begin_checkout.tpl',
'position' => 150
],
// Add payment info
// We add it into checkout_order_main ( checkout/order.tpl ) to make sure a payment is actually added;
// we'll also do it like that in the future for add_shipping_info ( not planed yet )
[
'template' => 'page/checkout/order.tpl',
'block' => 'checkout_order_main',
'file' => '/Application/views/blocks/add_payment_info.tpl',
'position' => 150 'position' => 150
], ],
], ],
'events' => [ 'events' => [
'onActivate' => '\D3\GoogleAnalytics4\Setup\Events::onActivate', 'onActivate' => '\D3\GoogleAnalytics4\Setup\Events::onActivate',
'onDeactivate' => '\D3\GoogleAnalytics4\Setup\Events::onDeactivate', 'onDeactivate' => '\D3\GoogleAnalytics4\Setup\Events::onDeactivate',
], ],
]; ];