google-adsense icon indicating copy to clipboard operation
google-adsense copied to clipboard

Warning: `withDefaults()` is unnecessary when using `defineProps()` with destructuring

Open nexoscreator opened this issue 1 year ago • 6 comments

I am encountering a warning when using the @nuxtjs/google-adsense module in my Nuxt 3 project. The warning indicates that withDefaults() is unnecessary when defineProps() is used with destructuring. Here are the details:

Warning Message:

 WARN  [@vue/compiler-sfc] withDefaults() is unnecessary when using destructure with defineProps().
Reactive destructure will be disabled when using withDefaults().
Prefer using destructure default values, e.g., const { foo = 1 } = defineProps(...).

node_modules/@nuxtjs/google-adsense/dist/runtime/components/Adsbygoogle.vue
11 |    hideUnfilled,
12 |    includeQuery,
13 |  } = withDefaults(defineProps<{
   |      ^^^^^^^^^^^^
14 |    adClient?: string
15 |    adSlot?: string | null

Environment:

Nuxt Version: ^3.14.1592 Module Version: "^3.0.0", Node Version: v20.15.0

nexoscreator avatar Dec 01 '24 15:12 nexoscreator

+1

Kokleng-Dev avatar Jan 02 '25 07:01 Kokleng-Dev

Any updates on this?

frixou89 avatar Jan 19 '25 07:01 frixou89

Have same issue. Any solution?

superdiazzz avatar Jan 23 '25 07:01 superdiazzz

use @nuxt/scripts for Google Adseen or Google Anylists and more

nexoscreator avatar Jan 23 '25 17:01 nexoscreator

use @nuxt/scripts for Google Adseen or Google Anylists and more

Do you know how to applied Google adsense with @nuxt/scripts?

superdiazzz avatar Jan 24 '25 13:01 superdiazzz

Do you know how to applied Google adsense with @nuxt/scripts?

How to Apply Google AdSense with @nuxt/scripts

To integrate Google AdSense using @nuxt/scripts, follow these steps:


1. Install @nuxt/scripts

Add the @nuxt/scripts module to your Nuxt project by running:

npx nuxi@latest module add scripts

2. Configure nuxt.config.ts

In your nuxt.config.ts file, include the following configuration to enable Google AdSense:

export default defineNuxtConfig({
  modules: ['@nuxt/scripts'],
  scripts: {
    registry: {
      googleAdsense: {
        client: 'ca-pub-xxxxxxxxxxxx', // Replace with your Google AdSense client ID
      },
    },
  },
});

3. Add the Google AdSense Component

You can use the built-in ScriptGoogleAdsense component in your Vue templates:

<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-..."  <!-- Replace with your Google AdSense client ID -->
    data-ad-slot="..."           <!-- Replace with your Ad Slot ID -->
  />
</template>

4. Handle Ad Blockers (Optional)

To gracefully handle users with ad blockers, leverage the #error slot to display a fallback message:

<template>
  <ScriptGoogleAdsense
    data-ad-client="ca-pub-..."
    data-ad-slot="..."
  >
    <template #error>
      <!-- Fallback message -->
      Please support us by disabling your ad blocker.
    </template>
  </ScriptGoogleAdsense>
</template>

5. Verify Site Ownership (Optional)

For site ownership verification, you can use the useScriptGoogleAdsense composable and add a meta tag in your <head> section:

const adsense = useScriptGoogleAdsense({
  client: 'ca-pub-<your-id>',
});
<meta name="google-adsense-account" content="ca-pub-<your-id>">

Required Tags

To ensure proper functionality, provide the following mandatory attributes:

  • data-ad-client: Your Google AdSense Client ID (e.g., ca-pub-xxxxxxxxxxxx).
  • data-ad-slot: Your Ad Slot ID.

Additional Resources

For more details, refer to the Official Documentation.

nexoscreator avatar Jan 24 '25 14:01 nexoscreator

Yea but .. does nuxt/script implementation serve "test" ads ? I don't want to do the rountrip-to-production dance again , to test/adjust ads functionality. My needs are peculiar .. i do not want to toss ads at random.

bloor avatar Apr 28 '25 11:04 bloor

@nexoscreator How come you deleted the PR addressing this issue?

saifahn avatar Jul 18 '25 05:07 saifahn