The Google tag code is not present

I installed the form and configured as well as instructions, the result does not change, no code was inserted on the pages of the site with the result with the non -functional Google tag

How I configured:

I added a container with my id
Advanced default settings
All Paths
All Roles
No block visibility group
and Other Default Settings
The only thing I tried is on content type: without checking anything (which I suppose means adding the tag everywhere) and cheking some content content type only.

In Google Tag Manager Settings I tried to:
Disable compact the javascript snippet
Disable includes The Snipper As a file

I also tried to disable modules that could give problems such advagg or cookie manager, but nothing has changed.

I tried the dev version, and nothing has changed.

Suggestions?

Issue fork google_tag-3345719

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sistro created an issue. See original summary.

solotandem’s picture

try checking a content type (or all of them)

sistro’s picture

I have already tried naturally!

tnx!

sistro’s picture

Problem solved!

It was my problem in the configuration and not in the module, of course!

For anyone having the same problem:
review the google tag manager module settings
if you use cookie consent manager make sure it does not block the google tag
and above all clean the browser cookies!!

Problem solved.

It was my problem in the configuration and not in the form, of course!

For anyone having the same problem:
review the google tag manager module settings
if you use cookie consent manager make sure it does not block the google tag
and above all clean the browser cookies!!

The only doubt on the module and a suggestion for future releases is in the "content type" section in the container settings. It would be useful to write "if none is enabled, the tag will be shown everywhere" (even if I have bypassed the mistake by trying the various settings (my problem was not in the configuration but elsewhere))

mglaman’s picture

Version: 8.x-1.6 » 2.0.x-dev
Status: Active » Fixed
hanoii’s picture

Category: Support request » Bug report
Priority: Minor » Critical
Status: Fixed » Active

I think there's a critical issue with this on 2.0.0

The issue should be easy to reproduce.

- Add a single google tag with no condition
- Add a node without any taxonomy (or look at a page that's not a node)

And the google tag is not added.

I spent quite a bit of time trying to figure this out. The reason is that the empty conditions are stored in the config entity, thus requiring the element in the context (i.e. a vocabulary is expected to be gathered from the route, which is not possible if the node doesn't have any term).

I then started to look why this was happening and comparing with other visibility logic like block (which I assume is where most of the code/logic has been taken from) and found that one thing was not being done:

https://git.drupalcode.org/project/drupal/-/blob/af1eb719451a296bd2d7f1d...

When you add this, the conditions are stored properly and I tried to understand why it happens. The reason seems to be that the negate checkbox when coming from the form is 0 (numeric 0) which is then strictly compared to false on:

https://git.drupalcode.org/project/drupal/-/blob/af1eb719451a296bd2d7f1d...

so It fails to remove it when saved just once.

However, it seems that by saving it twice (one on the submit handler and they by the entityform save method()

https://git.drupalcode.org/project/google_tag/-/blob/af8ad2037b4865f5c20...

The first time it's stored, the config is updated internally to match store schema (0 becomes false), so the second time the config entity is saved, the previous code works and the conditions is ps properly filtered and stored as empty (if no conditions obviously) so now the context is no longer required.

Basically, with no conditions the tag should be displayed everywhere.

hanoii’s picture

Status: Active » Needs review

MR created

hanoii’s picture

Component: Documentation » Code
shaunole’s picture

I can confirm that I was able to reproduce the reported issue and the MR resolved it.

amangrover90’s picture

Status: Needs review » Reviewed & tested by the community

MR resolved the issue for a use case when tag container is saved with no conditions.

mglaman’s picture

Crediting shaunole for testing

  • mglaman committed 9561bcf2 on 2.0.x authored by hanoii
    Issue #3345719 by hanoii, mglaman, amangrover90, sistro, solotandem,...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Merged! We'll make a release after a few more fixes

alexandersluiter’s picture

I am having issues with this with the group_type condition provided by the Group module. Even with this MR, it is still coming back as a condition to check. Diving into it, more to come.

mglaman’s picture

@alexandersluiter want to open a new issue? We're leveraging the core condition plugins and instances provided by modules. It should "just work"

alexandersluiter’s picture

Will do. I'm trying to figure out which module is the offending one yet. Will create new issue here if it turns out to be this one.

nicholass’s picture

I experienced the same difficulty in trying to get tracking code to show up on my site, I narrowed it down I think to the combination of "context" related modules. Specifically I think the drupal/context:4.x has some kind of default condition that makes it never show.

Only after I uninstalled all these (context was last, and I think the culprit) did the tag start to appear. (Core 9.5.8). After each module I removed, I uninstalled/reinstalled google_tag and saved my Google tag ID on the config page, then tested the site to see if I could find the tag.

  1. https://www.drupal.org/project/rules
  2. https://www.drupal.org/project/context_entity_field
  3. https://www.drupal.org/project/context_metadata
  4. https://www.drupal.org/project/context

Update: It seems to mainly be project/rules and project/context_entity_field, when either of those are installed, saving the `/admin/config/services/google-tag` from after adding only the Google Tag ID, causes the configuration YML to save with "conditions: {}" which cause the gtag to not be added.

Here are some examples of how the config changes after these modules are enabled, and the form is re-saved.

# When modules are uninstalled
dimensions_metrics: {  }
conditions: {  }
events:
# When entity_fiield_conditions is installed
dimensions_metrics: {  }
conditions:
  'entity_field:block_content':
    id: 'entity_field:block_content'
    field_name: body
    field_state: filled
    field_value: ''
    context_mapping:
      block_content: '@entity_route_context.entity_route_context:canonical_entity:block_content'
    negate: 0
  'entity_field:media':
    id: 'entity_field:media'
    field_name: bundle
    field_state: filled
    field_value: ''
    context_mapping:
      media: '@entity_route_context.entity_route_context:canonical_entity:media'
    negate: 0
  'entity_field:node':
    id: 'entity_field:node'
    field_name: body
    field_state: filled
    field_value: ''
    context_mapping:
      node: '@entity_route_context.entity_route_context:canonical_entity:node'
    negate: 0
  'entity_field:redirect':
    id: 'entity_field:redirect'
    field_name: created
    field_state: filled
    field_value: ''
    context_mapping:
      redirect: '@entity_route_context.entity_route_context:canonical_entity:redirect'
    negate: 0
  'entity_field:taxonomy_term':
    id: 'entity_field:taxonomy_term'
    field_name: changed
    field_state: filled
    field_value: ''
    context_mapping:
      taxonomy_term: '@entity_route_context.entity_route_context:canonical_entity:taxonomy_term'
    negate: 0
  'entity_field:token_custom':
    id: 'entity_field:token_custom'
    field_name: content
    field_state: filled
    field_value: ''
    context_mapping:
      token_custom: '@entity_route_context.entity_route_context:canonical_entity:token_custom'
    negate: 0
  'entity_field:webform_submission':
    id: 'entity_field:webform_submission'
    field_name: changed
    field_state: filled
    field_value: ''
    context_mapping:
      webform_submission: '@entity_route_context.entity_route_context:canonical_entity:webform_submission'
    negate: 0
  'entity_field:menu_link_content':
    id: 'entity_field:menu_link_content'
    field_name: bundle
    field_state: filled
    field_value: ''
    context_mapping:
      menu_link_content: '@entity_route_context.entity_route_context:canonical_entity:menu_link_content'
    negate: 0
events:
  

# when rules is installed
  dimensions_metrics: {  }
conditions:
  rules_data_is_empty:
    id: rules_data_is_empty
    negate: 0
    context_mapping:
      data: '@language.current_language_context:language_interface'
  rules_node_is_published:
    id: rules_node_is_published
    negate: 0
    context_mapping:
      node: '@entity_route_context.entity_route_context:canonical_entity:node'
  rules_entity_is_new:
    id: rules_entity_is_new
    negate: 0
    context_mapping:
      entity: '@entity_route_context.entity_route_context:canonical_entity'
  rules_node_is_sticky:
    id: rules_node_is_sticky
    negate: 0
    context_mapping:
      node: '@entity_route_context.entity_route_context:canonical_entity:node'
  rules_node_is_promoted:
    id: rules_node_is_promoted
    negate: 0
    context_mapping:
      node: '@entity_route_context.entity_route_context:canonical_entity:node'
  rules_user_has_role:
    id: rules_user_has_role
    negate: 0
    context_mapping:
      user: '@entity_route_context.entity_route_context:canonical_entity:user'
      roles: '@entity_route_context.entity_route_context:canonical_entity:user_role'
  rules_data_comparison:
    id: rules_data_comparison
    negate: 0
    context_mapping:
      data: '@language.current_language_context:language_interface'
      value: '@language.current_language_context:language_interface'
  rules_user_is_blocked:
    id: rules_user_is_blocked
    negate: 0
    context_mapping:
      user: '@entity_route_context.entity_route_context:canonical_entity:user'
events:
mglaman’s picture

@NicholasS can you open a bug? Something like "Condition plugins not evaluated properly when using Context". This needs some debugging.

hanoii’s picture

conditions: {} means no conditions, so the tag should be displayed always, is that not what you are experiencing.

nicholass’s picture

@hanoii - Yes its only working when conditions: {} is empty. When either https://www.drupal.org/project/rules or
https://www.drupal.org/project/context_entity_field are installed I can't get the gtag to show, since those modules add conditions which their defaults appear to cause the gtag to not be added. Its odd since my blocks/visibility have been fine with these modules installed, just not gtag.

@mglaman - Ill open an issue.

nicholass’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tzt20’s picture

I appreciate the work on this. The fix in the MR works for me. I'd appreciate this fix moving into a new release soon if possible. I spent quite a bit of time on this, and I imagine others will too. With Acquia's notice to upgrade, I imagine more users will encounter this problem. Thanks again.

hanoii’s picture

@tzt20 the latest 2.0.2 includes these fixes.

chris matthews’s picture

Issue tags: -

I'm on 2.0.2. When testing, I'm still getting: "Your Google tag wasn't detected on your website."

At /admin/config/services/google-tag, I have

Added my tag ID

Custom dimensions and metrics = None

Events

  • Custom event = Enabled
  • User registration = Enabled
  • Search = Enabled
  • Login = Enabled
  • Generate lead = Enabled
  • Purchase (Webform) = Enabled

Conditions

  • Response Code = Null
  • Request Path = Null
  • User Role = Anonymous user
  • Webforms = Null
  • Content type = Null
  • Vocabulary = Null
  • Webform = Null

Check this checkbox to enable Tag Container. = Enabled

=====
EDIT: Looks like the issue was I had "Collect Universal Analytics events" disabled

srdtwc’s picture

I believe I am encountering this error.

I am trying to use google_tag 2.0.2 with a tag ID begging with "GTM-". The only setting I've changed is that User Role is only Anonymous User.

When I use https://tagassistant.google.com/ It says "no tags found". I seem to be able to us tags begging with "AW-" and "G-" though, so the issue is specifically with a tag beginning with "GTM-"

sivamallareddy changed the visibility of the branch 3345719-google-tag-code to hidden.