FewCookies

Install with AI

How do I add a GDPR cookie banner to Ruby on Rails with an AI assistant?

Copy the prompt below into an AI coding assistant — Claude Code, Cursor, GitHub Copilot, Codex or Windsurf — open inside your Ruby on Rails project. It adds the FewCookies consent banner in the right place for Ruby on Rails, links your hosted legal pages, and verifies that no tracker fires before consent. FewCookies is €6/month, tax included, with a 7-day no-card trial.

Copy the prompt below into an AI coding assistant — Claude Code, Cursor, GitHub Copilot, Codex or Windsurf — open inside your Ruby on Rails project. It adds the FewCookies consent banner in the right place for Ruby on Rails, links your hosted legal pages, and verifies that no tracker fires before consent. FewCookies is €6/month, tax included, with a 7-day no-card trial.

The copy-paste prompt

Replace cg_YOUR_API_KEY with your real key from the dashboard, then paste the whole prompt into an AI assistant:

You are working in my Ruby on Rails project. Integrate the FewCookies cookie-consent widget (GDPR consent banner + tracker blocking) and link my hosted legal pages. Make the smallest change that satisfies every rule below.

## 1. Add the consent widget

Insert this exact script tag — do not change or reformat any attribute:

<script id="cookieguard-script" src="https://fewcookies.com/widget.js" data-api-key="cg_YOUR_API_KEY" data-blocking-mode="auto"></script>

Where: app/views/layouts/application.html.erb, inside <head>, above javascript_importmap_tags / javascript_include_tag.

Rules:
- The tag must appear in the initial HTML response (server-rendered or static), inside <head>, before any analytics or marketing tags (Google Analytics, Tag Manager, Meta Pixel, Hotjar, …).
- Keep it synchronous: do NOT add async, defer, or type="module", and do not lazy-load or dynamically inject it — it must run before trackers so it can block them until consent.

## 2. Link the legal pages in the footer

Add these links to the site footer (with target="_blank" rel="noopener"), matching the footer's existing markup and styling:
- Cookie policy: https://fewcookies.com/p/cg_YOUR_API_KEY/cookies
- Privacy policy: https://fewcookies.com/p/cg_YOUR_API_KEY/privacy
- Terms & conditions: https://fewcookies.com/p/cg_YOUR_API_KEY/terms
If the footer already links to self-hosted versions of these documents, ask me before replacing them.

## 3. Gate any inline tracking snippets (only if present)

The widget auto-blocks known trackers loaded via script src, but inline snippets pasted directly into the HTML can fire once before it neutralises them. If you find inline analytics/marketing snippets (gtag bootstrap, fbq, Hotjar init, TikTok pixel, …), convert each one to manual mode by changing its opening tag to:

<script type="text/plain" data-cookieguard="analytics">

Use data-cookieguard="analytics", "marketing", or "functional" to match each script's purpose. Leave strictly-necessary scripts untouched. If there are no inline tracking snippets, skip this step.

## 4. Verify

- Build or start the app and inspect the raw page source (view-source or curl, not devtools after JS runs): the tag must be present in <head> with id, data-api-key, and data-blocking-mode intact.
- Load a page in a browser: the consent banner appears on first visit.
- In the console, window.CookieGuard is defined and window.CookieGuard.show() reopens the banner.
- On a fresh/incognito visit, no analytics or marketing requests fire before consent is given (check the Network tab).

Report the result of each verification when you are done.

The resulting snippet

The assistant inserts exactly this tag (synchronous, in <head>):

<script id="cookieguard-script" src="https://fewcookies.com/widget.js" data-api-key="cg_YOUR_API_KEY" data-blocking-mode="auto"></script>

Step by step

  1. Copy the prompt. Copy the install prompt above. It already contains the exact script tag, with your cg_YOUR_API_KEY placeholder to replace, and the footer legal-page links.
  2. Paste it into an AI assistant. Paste the prompt into your coding assistant (Claude Code, Cursor, GitHub Copilot, Codex or Windsurf), open inside your Ruby on Rails project, and let it work.
  3. Review the diff. Review the change it produces: the <script> tag in <head> (synchronous, no async/defer) and the footer links to your hosted policies.
  4. Confirm blocking. Open your site in a fresh window: the banner appears on first visit and no analytics or marketing tracker fires before consent (check the Network tab).

Where it goes in Ruby on Rails

For Ruby on Rails, the tag goes in app/views/layouts/application.html.erb, inside <head>, above javascript_importmap_tags / javascript_include_tag. The prompt handles that for you.

Works with any AI assistant

The prompt is tool-agnostic: Claude Code, Cursor, GitHub Copilot, Codex or Windsurf or any other assistant that edits files. Copy it once and use it in any Ruby on Rails project.

You need your own key

Create an account, add your site and copy your real cg_ key — then run the free scan to see which cookies fire before consent today.

Check your site for free →

Frequently asked questions

Where does the snippet go in Ruby on Rails?

In app/views/layouts/application.html.erb, inside <head>, above javascript_importmap_tags / javascript_include_tag. The prompt tells the assistant exactly this, so the tag lands in the initial HTML, before any tracker.

Does the banner actually block trackers before consent?

Yes. The FewCookies widget uses 3-layer pre-consent blocking (createElement proxy + MutationObserver + network interceptors, including iframes) and sends all four Google Consent Mode v2 signals in the correct order.

Which AI assistants can I use?

Any coding assistant that reads instructions and edits files — Claude Code, Cursor, GitHub Copilot, Codex or Windsurf or others. The prompt is always in English, because agents follow English instructions most reliably.

How much does FewCookies cost?

FewCookies is €6/month, tax included, flat, with a 7-day no-card trial. You create your key and run a free scan before paying anything.