Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚰ Update to Google Analytics 4 and Cleanup Deprecated Configurations #76

Merged
merged 3 commits into from
Nov 15, 2024
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
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# AMP Affiliately Jekyll Theme Changelog

<!-- markdownlint-disable MD024 -->

## v3.1.0 (2024-11-05)

### ✨ Features
Expand All @@ -14,6 +16,23 @@
- Created a new documentation page, "Footer Configuration," providing detailed guidance on customizing footer columns and options.
- Updated the "Config Guide" page to include the latest information about footer options, ensuring comprehensive user instructions.

## v3.0.1 (2024-11-15)

### ♻️ Refactors

- Refactored conditional check for `site.ga4` in `postproc-content.html`.
- Updated example configuration files to use GA4 Measurement ID.

### 🗑️ Removed/Deprecated

- Removed AddThis share buttons and related configurations from `_includes/blocks/share-buttons.html`, `_layouts/default.html`, `_layouts/post-left-sidebar.html`, and `_layouts/post.html`.
- Removed `addthis_inline_share_toolbox` styles from `_sass/old_files/main.scss`.
- Removed outdated Google Analytics configurations in `youtube.html` and `default.html`.

### 📝 Documentation

- Updated README and Front Matter Guide to reflect the removal of discontinued AMP AddThis components and services.
- Updated README and Config Guide to remove deprecated Google Analytics and highlight Google Analytics 4 (GA4).

## v3.0.0 (2024-09-29)

Expand All @@ -34,8 +53,6 @@
- Removed deprecated `gulp-minify-inline` task from `gulpfile.mjs`
- Removed deprecated `css2scss` task and `@gecka/styleflux` from the gulp pipeline.
- Removed overrides for `gulp` dependencies: `glob-watcher`, `minimatch`, `semver`, `set-value`, and `vinyl-fs`.
- Removed AddThis share buttons and related configurations from `_includes/blocks/share-buttons.html`, `_layouts/default.html`, `_layouts/post-left-sidebar.html`, and `_layouts/post.html`.
- Removed `addthis_inline_share_toolbox` styles from `_sass/old_files/main.scss`.

### 💚 CI/CD

Expand All @@ -57,7 +74,6 @@
- Updated the status badge for CodeQL action.
- Updated the status badge for Jekyll build workflow.
- Updated README to document the new Jekyll build workflow. Included details on the new workflow steps and configuration.
- Updated README.md and Front Matter Guide to reflect the removal of discontinued AMP AddThis components and services.

## v2.9.1 (2024-03-12)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ Read the procedures in the [Config Guide](https://chriskyfung.github.io/amp-affi

- Read **Google Services** in the [Config Guide](https://chriskyfung.github.io//amp-affiliately-jekyll-theme/config-guide/#-google-services) ↗. For the following:

- Google Analytics
- Google Analytics 4
- Google Adsense
- Google Custom Search Engine
- Google Tag Manager
- Google Custom Search Engine

#### Disqus Comments in AMP 💬

Expand Down
2 changes: 1 addition & 1 deletion _config-examples/project-page/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ amp_disqus:
cse_id: 011006674894885990812:tjln7k0nyjx

# Analytics
google_analytics: 'UA-72575541-9' # Google Analytics Tracking ID
ga4: 'G-HP4LN87NJE' # Google Analytics 4 Measurement ID
gtm: 'GTM-WQMQK3X' # Google Tag Manager ID

# Google Ads
Expand Down
2 changes: 1 addition & 1 deletion _config-examples/user-page/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ amp_disqus:
cse_id: 011006674894885990812:tjln7k0nyjx

# Analytics
google_analytics: 'UA-72575541-9' # Google Analytics Tracking ID
ga4: 'G-HP4LN87NJE' # Google Analytics 4 Measurement ID
gtm: 'GTM-WQMQK3X' # Google Tag Manager ID

# Google Ads
Expand Down
6 changes: 3 additions & 3 deletions _includes/blocks/postproc-content.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{%- comment -%}
Modify every link with an external URL with the followings:
- If `site.google_analytics` or `or site.ga4` is configured, add the attribute `data-vars-event-label` to the anchor tag for using AMP Google Analytics to track outbound link events
- If `site.ga4` is configured, add the attribute `data-vars-event-label` to the anchor tag for using Google Analytics 4 for AMP to track outbound link events
- If `site.target_blank` is configured, add rel="noopener noreferrer" and target="_blank" to the anchor tag
{%- endcomment -%}
{%- if site.google_analytics or site.ga4 or site.target_blank == true -%}
{%- if site.ga4 or site.target_blank == true -%}
{%- assign splited_by_a = page.content | split: '<a ' -%}
{%- assign modified_content_1 = splited_by_a | first -%}
{% for splited_a_part in splited_by_a offset:1 %}
Expand All @@ -18,7 +18,7 @@
{%- if a_tag_lastchar == '>' -%}
{%- assign a_inner = a_inner | append: '>' -%}
{%- endif -%}
{%- if site.google_analytics or site.ga4 -%}
{%- if site.ga4 -%}
{%- assign event_label = 'data-vars-event-label="' | append: a_href | append: '" ' -%}
{%- endif -%}
{%- if site.target_blank == true -%}
Expand Down
53 changes: 0 additions & 53 deletions _includes/youtube.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,6 @@
{% capture label %}youtu.be/{{ include.id }}{% endcapture %}
{%- endif -%}

{%- if site.google_analytics -%}
{{ include.indent }}<amp-analytics type="gtag" data-credentials="include"
{%- if site.consent == true %}
data-block-on-consent-purposes="analytics"
{% endif -%}
>
<script type="application/json">
{
"vars" : {
"gtag_id": "{{ site.google_analytics }}",
"config" : {
"{{ site.google_analytics }}": { "groups": "default" }
}
},
"triggers": {
"videoPlay": {
"on": "video-play",
"request": "event",
"selector": "amp-youtube[data-videoid='{{ include.id }}']",
"vars": {
"event_category": "AMP YouTube player (client-side)",
"event_name": "Video Started",
"event_label": "{{ label }}",
"method": "Google"
}
},
"videoPause": {
"on": "video-pause",
"request": "event",
"selector": "amp-youtube[data-videoid='{{ include.id }}']",
"vars": {
"event_category": "AMP YouTube player (client-side)",
"event_name": "Video Paused",
"event_label": "{{ label }}",
"method": "Google"
}
},
"videoEnded": {
"on": "video-ended",
"request": "event",
"selector": "amp-youtube[data-videoid='{{ include.id }}']",
"vars": {
"event_name": "Video Ended",
"event_category": "AMP YouTube player (client-side)",
"event_label": "{{ label }}",
"method": "Google"
}
}
}
}
</script>
{{ include.indent }}</amp-analytics>
{%- endif -%}
{%- if site.ga4 -%}
{{ include.indent }}<amp-analytics type="gtag" data-credentials="include"
{%- if site.consent == true %}
Expand Down
32 changes: 0 additions & 32 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,38 +268,6 @@ <h2 class="sr-only">Footer</h2>
<!-- End Footer -->
</div><!-- /.site-content -->

{%- if site.google_analytics -%}
<!-- Configure analytics to use gtag -->
<amp-analytics type="gtag" data-credentials="include"
{%- if site.consent == true %}
data-block-on-consent-purposes="analytics"
{% endif -%}
style="width:1px;height:1px;">
<script type="application/json">
{
"vars": {
"gtag_id": "{{ site.google_analytics }}",
"config": {
"{{ site.google_analytics }}": { "groups": "default" }
}
},
"triggers": {
"trackAnchorClicks": {
"selector": "a:not([href^='{{ site.url }}'])",
"on": "click",
"request": "event",
"vars": {
"event_category": "External Link",
"event_name": "${eventLabel}",
"event_label": "{{ page.url }}",
"method": "Google"
}
}
}
}
</script>
</amp-analytics>
{%- endif -%}
{%- if site.ga4 -%}
<amp-analytics type="gtag" data-credentials="include">
<script type="application/json">
Expand Down
4 changes: 1 addition & 3 deletions _posts/2021-08-02-config-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,11 @@ defaults:

| Attribute | Description |
| -----------------: | ----------------------------------------------------------------------------------------------------------------------- |
| `google_analytics` | <span>Deprecated</span>{:.badge.badge-default}<br> Your (`UA-`) Tracking ID. 💡 [Find your Google Analytics ID] |
| `ga4` | <span>v2.6.1</span>{:.badge.badge-success}<br> Your (`G-`{:plaintext} ) Measurement ID 💡. [Find your GA4 Measurement ID] |

[Find your Google Analytics ID]: https://support.google.com/analytics/answer/1008080#trackingID "Set up the Analytics global site tag - Analytics Help"
[Find your GA4 Measurement ID]: https://support.google.com/analytics/answer/12270356 "\[GA4\] Measurement ID - Analytics Help"

- When `google_analytics` is configured, an attribute called `data-vars-event-label` will be added to every `<a>` tag that links to an external URL by the post-processing of posts' content.
- When `ga4` is configured, an attribute called `data-vars-event-label` will be added to every `<a>` tag that links to an external URL by the post-processing of posts' content.

##### <i class="fab fa-searchengin fa-fw"></i> Google Custom Search Engine (CSE)

Expand Down
2 changes: 1 addition & 1 deletion _posts/2021-08-15-postprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

## Link Modifier

To enable outbound link tracking with Google Analytics in AMP, you need to insert a `data-vars-event-label` attribute to external links.
To enable outbound link tracking with Google Analytics 4 for AMP, you need to insert a `data-vars-event-label` attribute to external links.

Starting from <span class="badge badge-success">v2.0</span>, this theme replace the non-whitelist `jekyll-target-blank.rb` plugin with pure Liquid templating language to modify the links.

Expand Down