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

Doesn't seem possible to conditionally load gtag #1334

Closed
wuhhh opened this issue Jun 15, 2023 · 7 comments
Closed

Doesn't seem possible to conditionally load gtag #1334

wuhhh opened this issue Jun 15, 2023 · 7 comments
Labels

Comments

@wuhhh
Copy link

wuhhh commented Jun 15, 2023

Describe the bug

Following advice given on other issues here, I have the following in my default layout:

{% if craft.cookies.get('allowCookies') != 'true' %}
  {% do seomatic.script.get('gtag').include(false) %}
  {% do seomatic.script.get('googleTagManager').include(false) %}
  {% do seomatic.script.container().include(false) %}
  {% do seomatic.script.container().clearCache(true) %}
{% endif %}

FB Pixel, hubspot etc correctly disappear, however there is still a call made to https://www.googletagmanager.com/gtag/js?id=xxx

Screenshot 2023-06-15 at 12 20 06

Versions

  • Plugin version: 4.0.28
  • Craft version: 4.4.9 Solo
@wuhhh wuhhh added the bug label Jun 15, 2023
@khalwat
Copy link
Collaborator

khalwat commented Jun 16, 2023

Doing this:

  {% do seomatic.script.container().include(false) %}

will ensure that no scripts from SEOmatic are rendered. Are you sure this gtag script is actually coming from SEOmatic?

@wuhhh
Copy link
Author

wuhhh commented Jun 20, 2023 via email

khalwat added a commit that referenced this issue Jun 20, 2023
…de/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))
khalwat added a commit that referenced this issue Jun 20, 2023
…de/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))
@khalwat
Copy link
Collaborator

khalwat commented Jun 20, 2023

Addressed in: eae2cc4 & 60838de

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop as 3.4.58”,

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop-v4 as 4.0.29”,

Then do a composer clear-cache && composer update

@khalwat khalwat closed this as completed Jun 20, 2023
@jamesmacwhite
Copy link

FYI, I think this has caused a regression on noscript related areas for bodyJS see: #1346 since updating to 3.4.58

@khalwat
Copy link
Collaborator

khalwat commented Jul 19, 2023

Yes, you're right. #1346

@khalwat khalwat reopened this Jul 19, 2023
@khalwat khalwat closed this as completed Jul 19, 2023
khalwat added a commit that referenced this issue Jul 19, 2023
…ly include/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))"

This reverts commit 60838de.
khalwat added a commit that referenced this issue Jul 19, 2023
…ly include/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))"

This reverts commit eae2cc4.
@khalwat
Copy link
Collaborator

khalwat commented Jul 22, 2023

So I looked into this further after having to roll back the previous fix that had regressions.

If you put this Twig into the root of the template (not in a {% block %} tag:

    {% do seomatic.script.container().include(false) %}

It will work for you. The issue is that the body script is rendered in a different manner than the rest of the tags, because it can include raw HTML, and due to Twig Processing Order:

https://nystudio107.com/blog/twig-processing-order-and-scope

...the tags are rendered before your code that said not to include the tag is executed. Moving that code outside of the block will cause it to work as expected.

khalwat added a commit that referenced this issue Jul 22, 2023
…de/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))
khalwat added a commit that referenced this issue Jul 22, 2023
…de/exclude scripts that have body JavaScript via Twig, by unifying the rendering method ([#1334](#1334))
@khalwat
Copy link
Collaborator

khalwat commented Jul 22, 2023

I wasn't content with that quirk, so fixed the issue properly.

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop as 3.4.60”,

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop-v4 as 4.0.31”,

Then do a composer clear-cache && composer update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants