Only one 'enable_page_level_ads' allowed per page

Created on 27 August 2023, over 1 year ago

Problem/Motivation

Firefox inspector gives this error when adsense integration module is enabled:
Uncaught TagError: adsbygoogle.push() error: Only one 'enable_page_level_ads' allowed per page.

On those pages, where the adsense is exlcuded, there is no error.
I havent done any customizations, using Barrio bootstrap theme 5.5.12
Drupal 9.5.9 Php 8.1

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.3

Component

Code

Created by

🇫🇮Finland anaconda777

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @anaconda777
  • 🇲🇽Mexico koffer

    I get the same error in my site.

  • 🇧🇴Bolivia manuvelasco Bolivia

    Apparently the problem is for the push() method added in /adsense/templates/adsense-managed-page-level.html.twig
    For auto ads, the push() script is not needed.

    {% if not defer %}

    {% else %}
    {{ attach_library('adsense/adsense.adsbygoogle') }}
    {% endif %}
    {#

    #} {# (adsbygoogle = window.adsbygoogle || []).push({#} {# google_ad_client: "ca-{{ client }}",#} {# enable_page_level_ads: true#} {# });#} {#

    #}

  • First commit to issue fork.
  • Merge request !7Use updated auto ads code → (Open) created by jcnventura
  • 🇵🇹Portugal jcnventura

    Can you try the MR?

  • 🇫🇷France erwangel

    This MR worked for me. I don't have the "Only one 'enable_page_level_ads' allowed per page" error any more.

    I now have this Deprecated function: urldecode(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\adsense\Controller\CseResultsController->display() (line 77 of /path_to_site/web/modules/contrib/adsense/src/Controller/CseResultsController.php). Not sure it is related to the MR but I haven't noticed this before.

  • Status changed to RTBC 2 months ago
  • 🇺🇸United States jesss

    The MR is working for me to resolve this error.

    I am not seeing the deprecated function warning reported by @erwangel so I think that may have been related to something else.

Production build 0.71.5 2024