Antwort #1 am: 14. Juni 2018, 16:47:50
So,
ich versuche mal den Code auf gtag umzubauen. Es soll alles in das head-Element rein, deswegen setzte ich bei includes/extra/header/header_head/gtag.js.php an.
includes/extra/header/header_body/google_conversiontracking.js.php braucht man dann nicht mehr und in den template muss in der index.html der Code
{if $smarty.const.TRACKING_GOOGLEANALYTICS_ACTIVE == 'true'}
{googleanalytics account=$smarty.const.TRACKING_GOOGLEANALYTICS_ID}
{/if}
entfernt werden.
<?php// GOOGLE CONV. TRACKING$show_google_conversion_event = (basename($PHP_SELF) == FILENAME_CHECKOUT_SUCCESS
&& GOOGLE_CONVERSION
== 'true');if ($show_google_conversion_event) { require_once (DIR_FS_INC
.'get_order_total.inc.php'); $total = get_order_total
($last_order);}?><?php if (TRACKING_GOOGLEANALYTICS_ACTIVE
== 'true'): ?><script type="text/javascript">
// Set to the same value as the web property used on the site
var gaProperty = '
<?= GOOGLE_GOOGLEANALYTICS_ID
?>'\';
// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
<?php // cache analytics.js $cache_gs = DIR_FS_CATALOG
.'cache/gtag.js'; if (!is_file($cache_gs) || (time() - filemtime($cache_gs) > 3600)) { require_once(DIR_FS_INC
.'get_external_content.inc.php'); $source_gs = get_external_content
('https://www.googletagmanager.com/gtag/js', 2, false); if (file_put_contents($cache_gs, $source_gs, LOCK_EX
) !== false) { $gs = xtc_href_link
('cache/gtag.js', '', $request_type, false); } } elseif (is_file($cache_gs)) { $gs = xtc_href_link
('cache/gtag.js', '', $request_type, false); } $config_prop = ['anonymize_ip' => true]; if (TRACKING_GOOGLE_LINKID
== 'true'){ $config_prop['link_attribution'] = true; } if (TRACKING_GOOGLE_DISPLAY
== 'true'){ $config_prop['allow_display_features'] = true; } $config_prop_txt = json_encode($config_prop);?><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="
<?= isset($gs)?
$gs:'https://www.googletagmanager.com/gtag/js'?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '
<?= TRACKING_GOOGLEANALYTICS_ID
?>',
<?= $config_prop_txt ?>);
<?php if (GOOGLE_CONVERSION
): ?> gtag('config', '
<?= GOOGLE_CONVERSION_ID
?>',
<?= $config_prop_txt ?>);
<?php endif; ?></script>
<?php endif; ?><?php if ($show_google_conversion_event): ?><!-- Event snippet for Verkauf conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': '
<?= GOOGLE_CONVERSION_ID
?>/
<?= GOOGLE_CONVERSION_LABEL
?>',
'value':
<?= $total ?>,
'currency': 'EUR',
'transaction_id': ''
});
</script>
<?php endif; ?> Es bleiben noch ein paar Punkte offen:
Was haltet ihr davon? Kann man das so nutzen?