Files
wyczarujprezent.pl/modules/ecsgtmpro/views/templates/hook/gtm.tpl
2024-10-28 22:14:22 +01:00

64 lines
2.5 KiB
Smarty

{*
* 2022 ECSoft
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to dev.ecsoft@gmail.com so we can send you a copy immediately.
*
*
* @author ECSoft <dev.ecsoft@gmail.com>
* @copyright 2022 ECSoft
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of ECSoft
*}
<script data-keepinline="true">
var ecsGtmAjaxGetProductUrl = '{if !empty($ajaxGetProductUrl)}{$ajaxGetProductUrl nofilter}{/if}';
</script>
{include file="./gtm_script.tpl"}
<script data-keepinline="true">
{if $userIdConfig->async}
var ecsGtmProAjax = new XMLHttpRequest();
ecsGtmProAjax.onreadystatechange = function() {
if (ecsGtmProAjax.readyState == XMLHttpRequest.DONE ) {
if (ecsGtmProAjax.status == 200) {
var datalayerJs = ecsGtmProAjax.responseText;
try {
var datalayerObj = JSON.parse(datalayerJs);
dataLayer = dataLayer || [];
dataLayer.push(datalayerObj);
} catch(e) {
console.log("[ECSGTMPRO] error while parsing json");
}
{if $debug}
console.log('[ECSGTMPRO] DEBUG ENABLED');
console.log(datalayerObj);
document.addEventListener('DOMContentLoaded', function() {
if (document.getElementById("ecsgtmpro_debug_ajax")) {
document.getElementById("ecsgtmpro_debug_ajax").innerHTML = datalayerJs;
}
}, false);
{/if}
}
dataLayer.push({
event: '{$eventDlReady|escape:'htmlall':'UTF-8'}'
});
}
};
ecsGtmProAjax.open("GET", "{$asyncUrl nofilter}", true);
ecsGtmProAjax.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
ecsGtmProAjax.send();
{else}
dataLayer.push({
event: '{$eventDlReady|escape:'htmlall':'UTF-8'}'
});
{/if}
</script>