first commit
This commit is contained in:
191
web/templates/twig_compat/block.gtm.tpl
Normal file
191
web/templates/twig_compat/block.gtm.tpl
Normal file
@@ -0,0 +1,191 @@
|
||||
{get_contexts currency=1 language=1 country=1 assign="contexts"}
|
||||
{$activeCountry = $contexts.country->getActive()}
|
||||
{$activeCurrency = $contexts.currency->getActive()}
|
||||
{$activeLang = $contexts.language->getActive()}
|
||||
|
||||
{if (isDevelopment() || isFrontendTests()) && $dbcfg.analytics.google_tag_manager.reallyRun != 'Y'}
|
||||
{assign var="gtmId" scope="global" value='GTM-PFLLL74'}
|
||||
{else}
|
||||
{assign var="gtmId" scope="global" value=$dbcfg.analytics.google_tag_manager.ID}
|
||||
{/if}
|
||||
|
||||
{if $smarty.get.skip_gtm !== null}
|
||||
{assign var="gtmId" scope="global" value=false}
|
||||
{/if}
|
||||
|
||||
<!-- OLD GTM !-->
|
||||
{strip}
|
||||
{if $gtmId}
|
||||
{switch $gtm_type}
|
||||
{case "gtm"}
|
||||
{get_gtm_data assign='GTM'}
|
||||
<script defer>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
setTimeout(() => {
|
||||
page_data = {$GTM|json_encode:32 nofilter};
|
||||
page_data['page']['layout'] = window.innerWidth > 991 ? 'web' : window.innerWidth > 543 ? 'tablet' : 'mobil';
|
||||
|
||||
{* Standardni page data *}
|
||||
dataLayer.push(page_data);
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
|
||||
{if $GTM && $GTM.page->type == 'product'}
|
||||
{* Pokud preklikavam mezi variantami, nebo se nacita stranka s produktem/variantou, posilat product impressions *}
|
||||
<script src="{static_url url="/common/static/wpj/wpj.gtm.js"}?v2"></script>
|
||||
|
||||
<script>
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var hash = location.href.split("#")[1] || urlParams.get('id_variation') || "{array_key_first($body.product.variations.variations)}";
|
||||
|
||||
{* Variation impressions *}
|
||||
{if $body.product && $body.product.variations.variations|count}
|
||||
{* Pole pro pripravu dat pro varianty *}
|
||||
gtm_prva = { };
|
||||
{* Zakladni data stranky *}
|
||||
|
||||
{get_price_computer assign='priceComputer'}
|
||||
{foreach $body.product.variations.variations as $variation}
|
||||
{if $variation.delivery_time_index != '-1'}
|
||||
gtm_prva[{$variation.id}] = {
|
||||
'id': '{$body.product.id}_{$variation.id}',
|
||||
'idVariation': '{$variation.id}',
|
||||
'idProduct': '{$body.product.id}',
|
||||
'EAN': '{$variation.ean}',
|
||||
'variationName': '{$variation.title|trim|escape:javascript}',
|
||||
'code': '{$variation.code}',
|
||||
'price': {$priceComputer->getPrice($variation.productPrice)},
|
||||
'variationCode': '{$variation.variationCode}',
|
||||
'productCode': '{$body.product.productCode}',
|
||||
};
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
{* Odeslani impressions *}
|
||||
wpj.onReady.push(function () {
|
||||
$('input[name^=IDvariation], select#IDvariation').on('change', function () {
|
||||
gtm_getDetailImpressions($(this).val(), 'detailImpressionsVariation');
|
||||
});
|
||||
|
||||
if (hash != "") {
|
||||
variation = gtm_getVariation(hash);
|
||||
|
||||
product = $.extend(page_data['products'], variation);
|
||||
page_data = $.extend(page_data, { 'products': product });
|
||||
}
|
||||
|
||||
gtm_getDetailImpressions(hash, 'detailImpressions');
|
||||
});
|
||||
{else}
|
||||
{* Product impressions *}
|
||||
gtm_getDetailImpressions(hash, 'detailImpressions');
|
||||
{/if}
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{if $body.steps}
|
||||
{get_gtm_data type='ecommerce' method='Checkout' assign='ecommerce' data=['body' => $body]}
|
||||
{/if}
|
||||
|
||||
{if $body.orderSent}
|
||||
{get_gtm_data type='ecommerce' method='Purchase' assign='ecommerce' data=['body' => $body]}
|
||||
{/if}
|
||||
|
||||
{if $slider}
|
||||
{get_gtm_data type='ecommerce' method='PromotionImpression' assign='ecommerce' data=['slider' => $slider]}
|
||||
{/if}
|
||||
|
||||
{if $GTM && $GTM.page->type === 'searchResult'}
|
||||
{get_gtm_data type='ecommerce' method='SearchResult' assign='ecommerce'}
|
||||
{/if}
|
||||
|
||||
{if $ecommerce}
|
||||
<script defer>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
setTimeout(() => {
|
||||
dataLayer.push({$ecommerce|json_encode:32 nofilter});
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{block dataLayerBlock}
|
||||
{function pushAnalyticsSession}
|
||||
{get_session_value type=$type remove=true assign=value}
|
||||
{if $value}
|
||||
<script>
|
||||
window.dataLayer.push({
|
||||
event: 'success{$type|ucfirst}'
|
||||
{if is_array($value)},'data':{$value|json_encode:32 nofilter}
|
||||
{elseif $value !== true}, 'value': '{$value}'{/if}
|
||||
});
|
||||
</script>
|
||||
{/if}
|
||||
{/function}
|
||||
{function pushAnalyticsSessionAssign}
|
||||
{get_session_value type=$type remove=true assign=value}
|
||||
{if $value && is_array($value)}
|
||||
<script>
|
||||
window.dataLayer.push(Object.assign({ }, {
|
||||
event: 'success{$type|ucfirst}',
|
||||
}, {$value|json_encode:32 nofilter}));
|
||||
</script>
|
||||
{/if}
|
||||
{/function}
|
||||
|
||||
{pushAnalyticsSession type="login"}
|
||||
{pushAnalyticsSession type="logout"}
|
||||
{pushAnalyticsSession type="registration"}
|
||||
{pushAnalyticsSessionAssign type="newsletterSubscribe"}
|
||||
{/block}
|
||||
{/case}
|
||||
|
||||
<script>
|
||||
{case "form_conversion"}
|
||||
var formData = { };
|
||||
$.each($this.serializeArray(), function() {
|
||||
formData[this.name] = this.value;
|
||||
});
|
||||
dataLayer.push({
|
||||
event: "successSendForm",
|
||||
formData: formData
|
||||
});
|
||||
{/case}
|
||||
</script>
|
||||
|
||||
{case "addToCart"}
|
||||
{if $dbcfg.analytics.google_tag_manager.active_fe_events != 'Y'}
|
||||
{get_gtm_data method='AddToCart' type='ecommerce' assign='ecommerce' data=['addedToCart' => $addedToCart]}
|
||||
<script>dataLayer.push({$ecommerce|json_encode:32 nofilter});</script>
|
||||
{/if}
|
||||
{/case}
|
||||
|
||||
{case "addToWishList"}
|
||||
{get_gtm_data method='AddToWishList' type='ecommerce' assign='ecommerce' data=['addedToWishList' => $addedToWishList]}
|
||||
<script>
|
||||
dataLayer.push({$ecommerce|json_encode:32 nofilter});
|
||||
</script>
|
||||
{/case}
|
||||
|
||||
{case "dummy"}
|
||||
{* Dummy case, protoze nemuze bejt pred {/switch} nebo {default} jako posledni </script>, pada to pak na kompilaci. *}
|
||||
{/case}
|
||||
|
||||
{default}
|
||||
{if $slider}
|
||||
{get_gtm_data type='ecommerce' method='PromotionImpression' assign='ecommerce' data=['slider' => $slider]}
|
||||
{/if}
|
||||
|
||||
{if $ecommerce}
|
||||
<script defer>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
setTimeout(() => {
|
||||
dataLayer.push({$ecommerce|json_encode:32 nofilter});
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
{/if}
|
||||
{/switch}
|
||||
{/if}
|
||||
{/strip}
|
||||
Reference in New Issue
Block a user