Skip to content

Commit

Permalink
Move GA4 tracking code to <head>
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Sep 10, 2024
1 parent e503a1f commit b48f939
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 14 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
2 changes: 1 addition & 1 deletion config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ all:
# Google Analitycs:
# Set a GA property API key to track page view hits.
# E.g.: UA-1234567-89
google_analytics_api_key:
google_analytics_api_key: test_12354
# Set a GA custom dimension index numver (from the same property)
# to track the repository name as a dimension in page view hits
# of IOs, actors and repos index pages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="<?php echo $sf_user->getCulture(); ?>" dir="<?php echo sfCultureInfo::getInstance($sf_user->getCulture())->direction; ?>">
<head>
<?php echo get_component('default', 'googleAnalytics'); ?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include_title(); ?>
<?php echo get_component('default', 'tagManager', ['code' => 'script']); ?>
<link rel="shortcut icon" href="<?php echo public_path('favicon.ico'); ?>">
<%= htmlWebpackPlugin.tags.headTags %>
Expand Down

0 comments on commit b48f939

Please sign in to comment.