Skip to content

Commit

Permalink
Move GA4 tracking code to head element (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung authored Sep 10, 2024
1 parent e503a1f commit 199d159
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
11 changes: 11 additions & 0 deletions apps/qubit/modules/default/templates/_googleAnalytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php $gaKey = sfConfig::get('app_google_analytics_api_key', ''); ?>
<?php if (!empty($gaKey)) { ?>
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?> async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $gaKey; ?>"></script>
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?>>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<?php include_slot('google_analytics'); ?>
gtag('config', '<?php echo $gaKey; ?>');
</script>
<?php } ?>
12 changes: 0 additions & 12 deletions apps/qubit/templates/_footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,3 @@
</div>

</footer>

<?php $gaKey = sfConfig::get('app_google_analytics_api_key', ''); ?>
<?php if (!empty($gaKey)) { ?>
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?> async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $gaKey; ?>"></script>
<script <?php echo __(sfConfig::get('csp_nonce', '')); ?>>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<?php include_slot('google_analytics'); ?>
gtag('config', '<?php echo $gaKey; ?>');
</script>
<?php } ?>
1 change: 1 addition & 0 deletions apps/qubit/templates/layout.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
1 change: 1 addition & 0 deletions apps/qubit/templates/layout_1col.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
1 change: 1 addition & 0 deletions apps/qubit/templates/layout_2col.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
1 change: 1 addition & 0 deletions apps/qubit/templates/layout_3col.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
1 change: 1 addition & 0 deletions apps/qubit/templates/layout_basic.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
1 change: 1 addition & 0 deletions apps/qubit/templates/layout_wide.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<?php include_http_metas(); ?>
<?php include_metas(); ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_partial('default/googleAnalytics'); ?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include_title(); ?>
Expand Down

0 comments on commit 199d159

Please sign in to comment.