[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:
parent
6bdf788ebf
commit
79994eae69
3
Application/views/blocks/add_payment_info.tpl
Normal file
3
Application/views/blocks/add_payment_info.tpl
Normal file
@ -0,0 +1,3 @@
|
||||
[{$smarty.block.parent}]
|
||||
|
||||
[{include file="event/add_payment_info.tpl"}]
|
@ -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}]
|
@ -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
|
||||
### Added
|
||||
- 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
|
||||
### Fixed
|
||||
|
@ -18,9 +18,14 @@ namespace D3\GoogleAnalytics4\Modules\Core{
|
||||
}
|
||||
|
||||
namespace D3\GoogleAnalytics4\Modules\Application\Model{
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Payment;
|
||||
|
||||
class Category_parent extends \OxidEsales\Eshop\Application\Model\Category {}
|
||||
class Basket_parent extends \OxidEsales\Eshop\Application\Model\Basket {}
|
||||
class Manufacturer_parent extends \OxidEsales\Eshop\Application\Model\Manufacturer {}
|
||||
|
||||
class gtmPayment_parent extends Payment {}
|
||||
}
|
||||
|
||||
namespace D3\GoogleAnalytics4\Modules\Application\Controller{
|
||||
|
20
Modules/Application/Model/gtmPayment.php
Normal file
20
Modules/Application/Model/gtmPayment.php
Normal 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';
|
||||
}
|
||||
}
|
13
metadata.php
13
metadata.php
@ -16,6 +16,7 @@ use D3\GoogleAnalytics4\Modules\Application\Controller\d3GtmStartController;
|
||||
use D3\GoogleAnalytics4\Modules\Application\Controller\ThankYouController;
|
||||
use D3\GoogleAnalytics4\Modules\Application\Model\Basket as Basket;
|
||||
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\Core\ViewConfig;
|
||||
use OxidEsales\Eshop\Application\Component\BasketComponent as OEBasketComponent;
|
||||
@ -33,6 +34,7 @@ use OxidEsales\Eshop\Application\Controller\ThankYouController as OEThankYouCont
|
||||
use OxidEsales\Eshop\Application\Model\Basket as OEBasket;
|
||||
use OxidEsales\Eshop\Application\Model\Category as OECategory;
|
||||
use OxidEsales\Eshop\Application\Model\Manufacturer as OEManufacturer;
|
||||
use OxidEsales\Eshop\Application\Model\Payment as OEPayment;
|
||||
use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig;
|
||||
|
||||
$sMetadataVersion = '2.1';
|
||||
@ -65,6 +67,7 @@ $aModule = [
|
||||
OECategory::class => Category::class,
|
||||
OEBasket::class => Basket::class,
|
||||
OEManufacturer::class => Manufacturer::class,
|
||||
OEPayment::class => gtmPayment::class,
|
||||
|
||||
// Controller
|
||||
OEBasketController::class => BasketController::class,
|
||||
@ -88,6 +91,7 @@ $aModule = [
|
||||
'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/add_payment_info.tpl' => 'd3/googleanalytics4/Application/views/event/add_payment_info.tpl',
|
||||
'event/purchase.tpl' => 'd3/googleanalytics4/Application/views/event/purchase.tpl',
|
||||
'event/view_item_list.tpl' => 'd3/googleanalytics4/Application/views/event/view_item_list.tpl',
|
||||
'event/view_search_result.tpl' => 'd3/googleanalytics4/Application/views/event/view_search_result.tpl',
|
||||
@ -184,6 +188,15 @@ $aModule = [
|
||||
'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
|
||||
],
|
||||
],
|
||||
'events' => [
|
||||
'onActivate' => '\D3\GoogleAnalytics4\Setup\Events::onActivate',
|
||||
|
Loading…
Reference in New Issue
Block a user