Skip to content

Google Analytics: enable#22

Merged
gapry merged 6 commits intomainfrom
google-analytics
Dec 17, 2025
Merged

Google Analytics: enable#22
gapry merged 6 commits intomainfrom
google-analytics

Conversation

@gapry
Copy link
Owner

@gapry gapry commented Dec 17, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 17, 2025 19:27
@gemini-code-assist
Copy link

Summary of Changes

Hello @gapry, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces Google Analytics tracking to the website. It achieves this by creating a dedicated include file containing the Google Analytics script and then integrating this file into the main homepage layout. This change will allow for the collection of user interaction and traffic data on the site's homepage.

Highlights

  • New Google Analytics Include File: A new file, _includes/google-analytics.html, has been added. This file contains the necessary JavaScript code to integrate Google Analytics (gtag.js) with the tracking ID G-4DG3HSBT1T.
  • Google Analytics Integration: The _layouts/home.html file has been modified to include the newly created google-analytics.html snippet, thereby enabling Google Analytics tracking specifically on the homepage.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This PR adds Google Analytics tracking to the blog, but contains several critical security and privacy issues that must be addressed before merge:

Critical Issues:

  • Security Risk: Hardcoded Google Analytics tracking ID exposes sensitive configuration data
  • Privacy Violation: Analytics tracking without user consent violates privacy regulations (GDPR, CCPA)
  • Code Quality: Inconsistent indentation mixing tabs and spaces

Required Actions:

  1. Move the tracking ID to Jekyll configuration (_config.yml) using google_analytics_id variable
  2. Implement user consent mechanism or add privacy policy disclosure
  3. Fix indentation consistency throughout the JavaScript code
  4. Add newline at end of file

The Google Analytics implementation itself is functionally correct, but the security and privacy concerns must be resolved before this can be safely deployed to production.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

}

gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');

Choose a reason for hiding this comment

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

🛑 Security Risk: Hardcoded tracking ID exposes sensitive configuration data1. Store the Google Analytics ID in Jekyll configuration to prevent exposure in version control and enable different IDs for different environments.

Suggested change
gtag('config', 'G-4DG3HSBT1T');
gtag('config', '{{ site.google_analytics_id }}');

Footnotes

  1. CWE-200: Information Exposure - https://cwe.mitre.org/data/definitions/200.html

Comment on lines +4 to +11
window.dataLayer = window.dataLayer || [];

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

gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');

Choose a reason for hiding this comment

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

Inconsistent indentation mixing tabs and spaces creates maintainability issues. Use consistent spacing throughout the file.

Suggested change
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics_id }}');


gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');
</script> No newline at end of file

Choose a reason for hiding this comment

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

Add newline at end of file to follow POSIX standards and prevent potential issues with text processing tools.

Suggested change
</script>
</script>

layout: archive
---

{% include google-analytics.html %}

Choose a reason for hiding this comment

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

🛑 Privacy Violation: Google Analytics tracking is enabled without user consent or privacy policy disclosure. This violates GDPR and other privacy regulations. Consider implementing consent management or adding privacy policy references before tracking users.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables Google Analytics. I've identified a couple of areas for improvement. The analytics script contains a hardcoded tracking ID and ignores the anonymize_ip setting from your configuration; I've suggested using the variables from _config.yml instead. I also noted that analytics is only enabled for the homepage and suggested moving the include to a more general layout for site-wide tracking, potentially leveraging the built-in analytics feature of your Jekyll theme.

Comment on lines +1 to +12
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4DG3HSBT1T"></script>

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

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

gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');
</script> No newline at end of file

Choose a reason for hiding this comment

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

high

The Google Analytics tracking ID G-4DG3HSBT1T is hardcoded in this file. It's better to use the value from _config.yml (site.analytics.google.tracking_id) to avoid duplication and make maintenance easier. Additionally, the anonymize_ip: true setting in your _config.yml is currently being ignored. The suggested code below reads these values from your configuration file.

Suggested change
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4DG3HSBT1T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');
</script>
<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>

layout: archive
---

{% include google-analytics.html %}

Choose a reason for hiding this comment

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

medium

By including the Google Analytics script only in the home layout, you will only track visits to your homepage. Any visitors landing directly on other pages (like blog posts) will not be tracked. For site-wide tracking, this include should be placed in a more general layout file that all pages use, such as _layouts/default.html or _layouts/archive.html.

It's also worth noting that the minimal-mistakes-jekyll theme has built-in support for Google Analytics, which you've already configured in _config.yml. You might be able to simply use {% include analytics.html %} in your base layout and remove the custom _includes/google-analytics.html file, letting the theme handle the implementation.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enables Google Analytics tracking by creating a new include file with the Google Analytics gtag.js implementation and integrating it into the home page layout.

Key changes:

  • Added _includes/google-analytics.html with Google Analytics 4 tracking script
  • Integrated the analytics include into _layouts/home.html

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
_includes/google-analytics.html New file containing Google Analytics 4 (gtag.js) tracking script with hardcoded tracking ID
_layouts/home.html Added include statement to load Google Analytics on the home page

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +11
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4DG3HSBT1T"></script>

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

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

gtag('js', new Date());
gtag('config', 'G-4DG3HSBT1T');
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 ID is hardcoded in this template. This creates a maintainability issue as the ID appears both here and in _config.yml (lines 17-21). The tracking ID should be read from the site configuration using Liquid templating to maintain a single source of truth. Use site.analytics.google.tracking_id to reference the value from _config.yml.

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6
{% include google-analytics.html %}

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 include should be placed in the head section of the document (typically in the archive layout or a head include), not in the body of the home.html layout. Google Analytics scripts should be loaded in the head for proper tracking initialization before page content renders. Additionally, this implementation only adds tracking to the home page, but analytics should be site-wide. Consider adding the include to the archive layout or a shared head include that's used across all pages.

Suggested change
{% include google-analytics.html %}

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +10
function gtag() {
dataLayer.push(arguments);
}

gtag('js', new Date());
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.
@gapry
Copy link
Owner Author

gapry commented Dec 17, 2025

@copilot review

Copy link

Copilot AI commented Dec 17, 2025

@gapry I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you.

@gapry
Copy link
Owner Author

gapry commented Dec 17, 2025

/gemini review

@gapry
Copy link
Owner Author

gapry commented Dec 17, 2025

/q review the PR again

@amazon-q-developer
Copy link

Code Review Summary

I've reviewed the Google Analytics implementation in PR #22. The code adds basic Google Analytics tracking functionality, but there are several privacy, security, and implementation concerns that should be addressed:

Key Issues Found:

  1. Privacy Compliance: The implementation lacks user consent mechanisms required by GDPR, CCPA, and other privacy regulations. Analytics should only load after user consent.

  2. Security Considerations: Loading external scripts without integrity checks poses potential security risks1.

  3. Missing Configuration: No validation that the tracking ID is properly configured before loading the analytics script.

  4. File Formatting: Missing newline at end of _includes/head/custom.html.

Recommendations:

  • Implement a consent management system before loading analytics
  • Add error handling for missing configuration
  • Consider adding Content Security Policy headers
  • Add proper file formatting

The basic Google Analytics integration follows standard patterns, but privacy and security enhancements are needed for production use.

Footnotes

  1. CWE-829: Inclusion of Functionality from Untrusted Control Sphere - https://cwe.mitre.org/data/definitions/829.html

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables Google Analytics by adding custom tracking scripts. While this approach works, the minimal-mistakes-jekyll theme you're using provides built-in support for Google Analytics, which is configured via _config.yml. You have already correctly configured the necessary settings. Therefore, adding these new files (_includes/google-analytics.html and _includes/head/custom.html) is likely redundant. The theme's built-in implementation also correctly handles settings like anonymize_ip.

I recommend removing the two files added in this PR and letting the theme manage the analytics integration. This will simplify your project and make it easier to maintain.

However, if you have a specific reason to use a custom implementation, I have provided a comment with a suggested improvement to your script to make it more robust and to respect the privacy settings in your configuration.

Comment on lines +1 to +12
<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>

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 %}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +11
gtag('js', new Date());
gtag('config', '{{ site.analytics.google.tracking_id }}');
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 configuration file specifies anonymize_ip: true, but this setting is not being applied in the Google Analytics implementation. The gtag config call needs to include the anonymize_ip parameter to respect the privacy setting defined in the configuration. Without this, IP addresses will not be anonymized despite the configuration setting.

Suggested change
gtag('js', new Date());
gtag('config', '{{ site.analytics.google.tracking_id }}');
gtag('js', new Date());
{% if site.analytics.google.anonymize_ip %}
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': true });
{% else %}
gtag('config', '{{ site.analytics.google.tracking_id }}');
{% endif %}

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +12
<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>
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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1 @@
{% include google-analytics.html %} No newline at end of file
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 configuration in _config.yml specifies provider: "google-gtag" which suggests the minimal-mistakes theme may already have built-in Google Analytics support. Creating a custom implementation might result in duplicate tracking scripts being loaded if the theme's built-in analytics are also active. Consider verifying whether the theme's native analytics integration should be used instead, or ensure the theme's built-in analytics are disabled to prevent double-tracking.

Suggested change
{% include google-analytics.html %}
{% if site.analytics and site.analytics.provider != "google-gtag" %}
{% include google-analytics.html %}
{% endif %}

Copilot uses AI. Check for mistakes.
}

gtag('js', new Date());
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.
@gapry
Copy link
Owner Author

gapry commented Dec 17, 2025

/q review the PR again

@amazon-q-developer
Copy link

I've reviewed PR #22 for enabling Google Analytics. The implementation looks solid with good privacy practices. Here are my findings:

Positive aspects:

  • Privacy-first approach: The anonymize_ip: true configuration properly anonymizes visitor IP addresses, which is excellent for GDPR compliance
  • Conditional loading: The Jekyll conditional {% if site.analytics.google.tracking_id %} ensures analytics only loads when configured
  • Modern gtag implementation: Uses the current Google Analytics 4 (gtag.js) instead of legacy analytics.js
  • Async loading: The script loads asynchronously, preventing blocking of page rendering
  • Clean separation: Analytics code is properly separated into its own include file

🔧 Minor improvements:

  1. Missing newline: Both files are missing trailing newlines, which is a common convention
  2. Code formatting: Some minor spacing inconsistencies in the JavaScript

🛡️ Security considerations:

The implementation follows security best practices by:

  • Using HTTPS for the Google Tag Manager script
  • Implementing IP anonymization
  • Conditional loading based on configuration

The changes are ready for merge. The Google Analytics integration is implemented correctly with appropriate privacy safeguards.

@gapry
Copy link
Owner Author

gapry commented Dec 17, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom implementation for Google Analytics. However, the minimal-mistakes-jekyll theme provides built-in support for Google Analytics, which is activated via _config.yml. Since your configuration file already seems to be set up for this, the files added in this PR are likely redundant. This can lead to the Google Analytics script being loaded twice, which would skew your tracking data. I recommend removing the newly added files (_includes/google-analytics.html and _includes/head/custom.html) and relying on the theme's native integration.

@@ -0,0 +1 @@
{% include google-analytics.html %} No newline at end of file

Choose a reason for hiding this comment

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

high

The minimal-mistakes-jekyll theme automatically includes the Google Analytics script based on the configuration in _config.yml. Including it again here via _includes/head/custom.html is redundant and will likely cause the script to be loaded twice, which can corrupt your analytics data. It's recommended to remove this file and _includes/google-analytics.html to rely on the theme's built-in functionality.

}

gtag('js', new Date());
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': true });

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 %});

@gapry gapry merged commit 3e8c77f into main Dec 17, 2025
1 check passed
@gapry gapry deleted the google-analytics branch December 17, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants