Skip to content

googleAdsense

The googleAdsense registry script. It loads https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456 for the input of the example. Call useScriptGoogleAdsense(input, options?) from @hamur/scripts/<library> in a component, or list it under scripts.registry.googleAdsense to load it on every page.

Config keyscripts.registry.googleAdsense
FunctionuseScriptGoogleAdsense of @hamur/scripts/<library>
Input keysclient (required)
Default triggerclient
Scripthttps://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456
Hostspagead2.googlesyndication.com, googleads.g.doubleclick.net, tpc.googlesyndication.com
Bundleno
Collection proxyno
Consentnone

Example

ts
import { defineConfig } from "hamur";
import scripts from "@hamur/scripts";

export default defineConfig({
  framework: "react",
  modules: [scripts],
  scripts: {
    registry: {
      googleAdsense: { client: "ca-pub-1234567890123456" },
    },
  },
});

It loads after the app mounted and the first idle callback. The file is not bundled: it is served from the vendor's host. The script sends its own requests to the vendor.

Every key is checked when the config loads and again in useScriptGoogleAdsense: a wrong value stops the build with a message that starts with scripts.registry.googleAdsense. The registry list is on the registry page, and the shared options are in Scripts.