feat(01-purchase-data-layer): add post-payment purchase data layer

Phase 1 complete:

- move purchase event to order confirmation after successful payment

- add backend purchase payload builder for transaction and ticket lines

- remove premature purchase push from przelewy24 redirect view
This commit is contained in:
2026-04-19 20:32:38 +02:00
parent 752b6c653e
commit 9de042946a
17 changed files with 528 additions and 23 deletions

View File

@@ -1,3 +1,21 @@
<?php
$purchaseDataLayerJson = null;
if (is_array($this->purchase_data_layer ?? null)) {
$purchaseDataLayerJson = json_encode(
$this->purchase_data_layer,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_INVALID_UTF8_SUBSTITUTE
);
}
?>
<?php if($purchaseDataLayerJson) : ?>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(<?= $purchaseDataLayerJson; ?>);
</script>
<?php endif; ?>
<?php if($this->order_successful === true) : ?>
<script type="text/javascript">
$.alert({
@@ -175,4 +193,4 @@ $.alert({
</div>
</div>
</div>
</div>
</div>

View File

@@ -43,27 +43,7 @@ if($this->settings['p24']['sandbox']) {
</form>
<script type="text/javascript">
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: "<?= $this -> order['id'];?>",
value: <?= str_replace( ',', '.', $this -> order['order_price'] );?>,
currency: "PLN",
shipping: 0,
items: [
<? foreach ( $this -> order['tickets'] as $ticket ):?>
{
'id': <?= (int)$ticket['product_id'];?>,
'name': '<?= $ticket['name'];?>',
'quantity': <?= $ticket['quantity'];?>,
'price': <?= $ticket['price'];?>
}<? if ( $ticket != end( $this -> order['tickets'] ) ) echo ',';?>
<? endforeach;?>
]
}
});
$( document ).ready( function() {
$( "#form_data" ).submit();
});
</script>
</script>