Preferred Source Banner
This module adds a banner and inline button to your website that encourages visitors to add your site as a preferred source on Google. This feature can improve visibility in personalized search results and AI-powered search experiences. It includes local analytics, customizable display triggers, and flexible placement options.
Add as Preferred Source on Google plugin displays a banner and inline button on your website that directs visitors to Google’s preferred sources feature. When clicked, the banner takes users to Google’s preferences page where they can add your site as a preferred source for their personalized search results.
About Google Preferred Sources
Google Preferred Sources is a Google feature that allows users to select the websites they want to see more frequently in personalized search experiences, including Google Top Stories and Google Discover.
Why it matters
According to Search Engine Journal, Google Preferred Sources has expanded globally across supported languages, creating potential opportunities for publishers to strengthen audience engagement and visibility.
The feature has also expanded into AI-powered search experiences, including AI Overviews and AI Mode, as reported by Search Engine Journal.
Publishers, newsrooms and content-driven sites need a way to convert engaged readers into returning ones. This module provides that conversion surface as a first-class Drupal citizen: configured through the Configuration API, rendered through render arrays and Twig, placed through the Block system, and measured through a table you own.
Features
- Built-in private analytics. Every impression, click and dismissal is recorded in a dedicated database table on your own infrastructure. No tracking pixel, no cloud account, no data-sharing agreement. A report at
/admin/reports/preferred-sourceshows all-time totals, a 30-day breakdown with click-through rate, and your most-converting content. Visitor IP addresses are stored as SHA-256 hashes, never in clear text, and a configurable retention window purges old rows automatically through cron. - Intelligent scroll and time triggers. Rather than interrupting visitors the moment they arrive, the banner can wait until a configurable scroll depth is reached or a delay has elapsed — so it appears only when readers have demonstrated engagement. Scroll listeners are registered as passive and detach themselves after firing, keeping the main thread free.
- Anti-flash rendering. The banner is emitted hidden and revealed by JavaScript only after the dismissal check passes. On sites behind the Internal Page Cache or a CDN — where the same HTML is served to every visitor — this eliminates the flicker of a banner appearing and instantly vanishing for readers who already dismissed it.
- Granular dismissal persistence. Choose between Local Storage (with automatic cookie fallback for private browsing and quota errors) or cookies outright when server-side or CDN-level reads are required. Three frequency modes are available: always display, remember the dismissal for a configurable number of days, or hide only for the current browser session. Impressions are de-duplicated to one per visitor per day, so click-through rate stays meaningful across multi-page sessions.
- Automatic and manual placement. Enable automatic injection to reach every eligible page, or place the provided Block in any region or Layout Builder section — or both. Block instances inherit every global setting and override only what you change, so updating the destination URL site-wide remains a single edit.
- Precise display rules. Target or exclude pages by path (with wildcard and
<front>support, matched against both system paths and URL aliases), by content type, by individual node ID, and by user role. Administrative routes are always excluded. Separate desktop and mobile toggles let you suppress the banner where it would crowd a small viewport. - Clean separation of logic and presentation. No HTML is echoed anywhere in the codebase. Output flows through render arrays into a Twig template you can override in your theme, colors travel as CSS custom properties so stylesheets remain aggregatable, and all user-facing strings pass through
t()for translation. - Standards-compliant architecture. Dependency injection throughout the form, controllers and block plugin; a shared service that guarantees automatic and manual placements can never diverge; explicit cache tags and contexts so saving the settings form invalidates precisely the right pages; flood control on the public tracking endpoint; and an alter hook for modules that need to adjust the banner at runtime.
- Accessible and responsive by default. Semantic anchor markup for the call to action, a labelled close button, visible focus outlines,
prefers-reduced-motionsupport, and a layout that reflows cleanly on narrow viewports.
Post-Installation
Install the module as usual, then follow these steps:
- Configure the banner. Navigate to Configuration › Content authoring › Preferred Source Banner (
/admin/config/content/preferred-source). The form is organized into five tabs:- Content — banner text, optional subtitle, button label and target URL. The text and URL accept the
{site_name}and{site_url}shortcuts as well as standard Drupal tokens such as[site:name]. - Appearance — fixed position (top or bottom), background, text and accent colors, close button, and desktop/mobile visibility.
- Behavior — display trigger (immediate, scroll percentage or time delay), dismissal frequency, hide duration, and the persistence mechanism.
- Display rules — path mode and path list, content types, excluded node IDs, and excluded roles. These rules govern automatic injection only.
- Analytics — event recording, retention period, and the per-IP rate limit on the tracking endpoint.
- Content — banner text, optional subtitle, button label and target URL. The text and URL accept the
- Choose your placement strategy. Leave Display automatically enabled to inject the banner on every page that satisfies your display rules. Uncheck it if you would rather control placement entirely through blocks.
- Place the block (optional). Go to Structure › Block layout (
/admin/structure/block), click Place block in your chosen region, and select Preferred Source Banner from the Marketing category. In the block configuration form:- Pick a style: Card for a standalone unit in the page flow, Compact inline for sidebars and in-article placement, or Fixed bar to use the global position.
- Leave every field empty to inherit the global settings. Enable Override the text and URL or Override the colors only for the values this particular instance should differ on.
- Set a per-instance trigger if this placement should behave differently from the site default.
- Use the standard block visibility conditions to control which pages it appears on.
- Grant permissions. At
/admin/people/permissions, assign Administer the Preferred Source Banner to site administrators and View Preferred Source Banner analytics to anyone who should read the numbers without holding configuration rights. - Verify and measure. Load a front-end page to confirm the banner behaves as configured, then check Reports › Preferred Source Banner (
/admin/reports/preferred-source) for incoming impressions and clicks. Ensure cron runs regularly so the retention policy is applied.
Additional Requirements
- Drupal 10.3 or Drupal 11 (
^10.3 || ^11). The Block plugin uses PHP attributes, available from Drupal 10.2 onward; on 10.0 or 10.1 the attribute converts to the equivalent annotation in a single edit. - PHP 8.1 or later.
- Core modules only: System, Block and Path alias. Node and User are used when present but are not hard dependencies.
- No external dependencies. There are no Composer packages to install, no contributed modules to enable, no JavaScript libraries to download, and no CDN assets to load. The module ships one stylesheet and one vanilla JavaScript file built on
Drupal.behaviorsand core'sonce— no jQuery requirement, no build step. - No third-party services. Analytics are stored locally in your own database. No API key, no account registration, and no outbound request is ever made by the module.
Depends on
Dependencies of the latest stable release
- block Drupal core
- node Drupal core
- path_alias Drupal core
- system Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Releases
| Version | Type | Core | Notes | Release date | |
|---|---|---|---|---|---|
| 1.0.1 | Stable | 10–11 | Sep 24, 2026 |