feat(05-purchase-redirect-hardening): harden purchase redirect tracking
Phase 5 complete: - guard purchase event per transaction in sessionStorage - restore saved consent before GTM and purchase - add centered Przelewy24 countdown redirect
This commit is contained in:
@@ -45,6 +45,38 @@
|
||||
'ad_personalization': 'denied',
|
||||
'wait_for_update': 500
|
||||
});
|
||||
|
||||
(function() {
|
||||
function getCookie(name) {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = cookies[i].trim();
|
||||
if (cookie.indexOf(name + '=') === 0) {
|
||||
return decodeURIComponent(cookie.substring(name.length + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
var consent = JSON.parse(getCookie('cnp_consent'));
|
||||
var preferences = JSON.parse(getCookie('cnp_prefs'));
|
||||
|
||||
if (consent !== true || !Array.isArray(preferences)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gtag('consent', 'update', {
|
||||
'analytics_storage': preferences.indexOf('analytics') > -1 ? 'granted' : 'denied',
|
||||
'ad_storage': preferences.indexOf('marketing') > -1 ? 'granted' : 'denied',
|
||||
'ad_user_data': preferences.indexOf('marketing') > -1 ? 'granted' : 'denied',
|
||||
'ad_personalization': preferences.indexOf('marketing') > -1 ? 'granted' : 'denied'
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Consent Mode: could not restore saved cookie preferences.', error);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<!-- End Google Consent Mode v2 - default -->
|
||||
<!-- Google Tag Manager -->
|
||||
|
||||
@@ -10,9 +10,32 @@ if (is_array($this->purchase_data_layer ?? null)) {
|
||||
|
||||
<?php if($purchaseDataLayerJson) : ?>
|
||||
<script type="text/javascript">
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.dataLayer.push({ ecommerce: null });
|
||||
window.dataLayer.push(<?= $purchaseDataLayerJson; ?>);
|
||||
(function() {
|
||||
var purchaseDataLayer = <?= $purchaseDataLayerJson; ?>;
|
||||
var transactionId = purchaseDataLayer &&
|
||||
purchaseDataLayer.ecommerce &&
|
||||
purchaseDataLayer.ecommerce.transaction_id;
|
||||
var purchaseSent = false;
|
||||
|
||||
if (transactionId) {
|
||||
try {
|
||||
var storageKey = 'brzezovka_purchase_sent_' + transactionId;
|
||||
purchaseSent = sessionStorage.getItem(storageKey) === '1';
|
||||
|
||||
if (!purchaseSent) {
|
||||
sessionStorage.setItem(storageKey, '1');
|
||||
}
|
||||
} catch (error) {
|
||||
purchaseSent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!purchaseSent) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.dataLayer.push({ ecommerce: null });
|
||||
window.dataLayer.push(purchaseDataLayer);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -58,10 +81,39 @@ if($this->settings['p24']['sandbox']) {
|
||||
<input type="hidden" name="p24_method" value="227">
|
||||
<input type="hidden" name="p24_sign"
|
||||
value="<?= md5( $this -> przelewy24_hash . '|' . $merchant_id . '|' . ( $clientData['order_price'] * 100 ) . '|PLN|' . $crc_key );?>" />
|
||||
|
||||
<div class="container py-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-md-8 col-lg-6">
|
||||
<div class="alert alert-info text-center shadow-sm mb-0" role="alert">
|
||||
<h4 class="alert-heading mb-3">Przekierowanie do platnosci</h4>
|
||||
<p class="mb-2">Za chwile nastapi automatyczne przejscie do Przelewy24.</p>
|
||||
<p class="mb-0">
|
||||
Pozostalo
|
||||
<strong><span id="redirectCountdown">5</span> s</strong>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready( function() {
|
||||
$( "#form_data" ).submit();
|
||||
$(document).ready(function() {
|
||||
var secondsLeft = 5;
|
||||
var countdownElement = $("#redirectCountdown");
|
||||
|
||||
var countdownInterval = setInterval(function() {
|
||||
secondsLeft -= 1;
|
||||
countdownElement.text(secondsLeft);
|
||||
|
||||
if (secondsLeft <= 0) {
|
||||
clearInterval(countdownInterval);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
setTimeout(function() {
|
||||
$("#form_data").submit();
|
||||
}, 5000);
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user