Skip to content

Commit 199d159

Browse files
authored
Move GA4 tracking code to head element (#1869)
1 parent e503a1f commit 199d159

File tree

9 files changed

+18
-12
lines changed

9 files changed

+18
-12
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php $gaKey = sfConfig::get('app_google_analytics_api_key', ''); ?>
2+
<?php if (!empty($gaKey)) { ?>
3+
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?> async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $gaKey; ?>"></script>
4+
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?>>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag(){dataLayer.push(arguments);}
7+
gtag('js', new Date());
8+
<?php include_slot('google_analytics'); ?>
9+
gtag('config', '<?php echo $gaKey; ?>');
10+
</script>
11+
<?php } ?>

apps/qubit/templates/_footer.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,3 @@
1818
</div>
1919

2020
</footer>
21-
22-
<?php $gaKey = sfConfig::get('app_google_analytics_api_key', ''); ?>
23-
<?php if (!empty($gaKey)) { ?>
24-
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?> async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $gaKey; ?>"></script>
25-
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?>>
26-
window.dataLayer = window.dataLayer || [];
27-
function gtag(){dataLayer.push(arguments);}
28-
gtag('js', new Date());
29-
<?php include_slot('google_analytics'); ?>
30-
gtag('config', '<?php echo $gaKey; ?>');
31-
</script>
32-
<?php } ?>

apps/qubit/templates/layout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

apps/qubit/templates/layout_1col.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

apps/qubit/templates/layout_2col.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

apps/qubit/templates/layout_3col.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

apps/qubit/templates/layout_basic.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

apps/qubit/templates/layout_wide.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
56
<?php include_http_metas(); ?>
67
<?php include_metas(); ?>

plugins/arDominionB5Plugin/templates/_layout_start_webpack.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
33
<head>
4+
<?php echo get_partial('default/googleAnalytics'); ?>
45
<meta charset="utf-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1">
67
<?php include_title(); ?>

0 commit comments

Comments
 (0)