Skip to content

Commit

Permalink
Merge pull request #95 from chriskyfung:fixes/google-tags-and-ads
Browse files Browse the repository at this point in the history
🔧 Fix GA4 Configuration Logic, Enhance Conditional Handling, and Add Non-Personalized Ads Fallback
  • Loading branch information
chriskyfung authored Nov 30, 2024
2 parents 5fe76e3 + 5afe121 commit fd068e8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions _includes/blocks/ad-before-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<amp-ad width="100vw" height="200"
{%- if site.consent == true %}
data-block-on-consent-purposes="advertising"
data-npa-on-unknown-consent=true
{% endif -%}
type="adsense"
data-ad-client="{{ site.adsense.client_id }}"
Expand Down
16 changes: 11 additions & 5 deletions _includes/blocks/ga4-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
"vars": {
"gtag_id": "{{ site.ga4 }}",
"config": {
"{{ site.ga4 }}": { "groups": "default" }
},{%- if jekyll.environment != 'production' %}
"debug_mode": true,{% endif %}
"{{ site.ga4 }}": {
{%- if jekyll.environment != 'production' %}
"debug_mode": true,
{%- endif %}
"groups": "default"
}
},
"ampHost": "${ampdocHost}"
},
"triggers": {
Expand All @@ -43,7 +47,8 @@
"method": "Google",
"link_url": "${eventLabel}",
"outbound": true
}{%- if include.yt_selectors %}
}
{%- if include.yt_selectors %}
},
"videoPlay": {
"on": "video-play",
Expand Down Expand Up @@ -106,7 +111,8 @@
"video_provider": "youtube",
"video_title": "${videoTitle}",
"video_url": "${videoUrl}"
}{% endif %}
}
{%- endif %}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions _includes/blocks/site_content_postproc.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
Date: 2024-11-23
{%- endcomment -%}

{%- assign amp_youtube_selectors = nil -%}

{%- if site.ga4 and page.amp.youtube -%}
{%- assign segments = include.content | split: '<amp-youtube ' -%}
{%- assign processed_head = segments[0] -%}
Expand Down Expand Up @@ -39,11 +37,15 @@
{%- endif -%}
{%- endfor -%}
{%- assign selectors = selectors | append: ' "amp-youtube[data-videoid=' | append: "'" | append: video_id | append: "'" | append: ']"' -%}

{%- endfor -%}

{%- assign amp_youtube_selectors = selectors | strip | replace: ' "' , ', "' -%}

{%- endif -%}

{% include blocks/ga4-config.html yt_selectors=amp_youtube_selectors %}

{%- unless amp_youtube_selectors contains 'amp-youtube' -%}
{% include blocks/ga4-config.html %}
{%- else -%}
{% include blocks/ga4-config.html yt_selectors=amp_youtube_selectors %}
{%- endunless -%}
1 change: 1 addition & 0 deletions _includes/sidebar/custom/ad-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ <h3><span>Ads</span></h3>
<amp-ad width="100vw" height="292"
{%- if site.consent == true %}
data-block-on-consent-purposes="advertising"
data-npa-on-unknown-consent=true
{% endif -%}
type="adsense"
data-ad-client="{{ site.adsense.client_id }}"
Expand Down
1 change: 1 addition & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<amp-auto-ads type="adsense" data-ad-client="{{ site.adsense.client_id }}"
{%- if site.consent == true %}
data-block-on-consent-purposes="advertising"
data-npa-on-unknown-consent=true
{% endif -%}
{%- if jekyll.environment != 'production' -%}
data-adtest="on"
Expand Down

0 comments on commit fd068e8

Please sign in to comment.