Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions _includes/google-analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% if site.analytics.google.tracking_id %}

<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics.google.tracking_id }}"></script>

<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}

gtag('js', new Date());
Comment on lines +8 to +12
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: The function declaration uses spaces for indentation while the rest of the script uses tabs. This should be standardized to match the project's coding style. Either use all tabs or all spaces throughout the script.

Suggested change
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

Copilot uses AI. Check for mistakes.
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': true });
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The anonymize_ip option is configured both in _config.yml (line 21) and hardcoded here. This creates a maintenance issue where the configuration exists in two places. Consider using the config value: {{ site.analytics.google.anonymize_ip }} instead of hardcoding true to maintain a single source of truth.

Suggested change
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': true });
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': {{ site.analytics.google.anonymize_ip }} });

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line hardcodes the anonymize_ip option. The theme's built-in implementation handles this more flexibly by checking the site.analytics.google.anonymize_ip setting from _config.yml. This makes the theme's version more maintainable, as configuration changes only need to be made in one place. This is another reason to prefer the theme's native analytics integration over a custom implementation.

  gtag('config', '{{ site.analytics.google.tracking_id }}'{% if site.analytics.google.anonymize_ip %}, { 'anonymize_ip': true }{% endif %});

</script>
Comment on lines +3 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This analytics script can be improved in two ways:

  1. Respect anonymize_ip setting: Your _config.yml has anonymize_ip: true, but this script doesn't apply it. This is important for user privacy.
  2. Add robustness check: The script should only be rendered if a tracking_id is present in the configuration to avoid errors.

The suggested code below addresses both points by wrapping the script in a conditional and adding the anonymize_ip parameter.

Suggested change
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics.google.tracking_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ site.analytics.google.tracking_id }}');
</script>
{% if site.analytics.google.tracking_id %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics.google.tracking_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ site.analytics.google.tracking_id }}'{% if site.analytics.google.anonymize_ip %}, { 'anonymize_ip': true }{% endif %});
</script>
{% endif %}

Comment on lines +3 to +14
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Google Analytics tracking code is being included unconditionally without checking if analytics is enabled or if a tracking ID is configured. Consider wrapping the analytics code in a conditional check to only load when the tracking_id is present. This prevents loading tracking scripts unnecessarily and improves privacy.

Copilot uses AI. Check for mistakes.

{% endif %}
1 change: 1 addition & 0 deletions _includes/head/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include google-analytics.html %}