TermsBox
PricingBlog
LoginGet Started
PricingBlogLogin
Get Started
  1. Home
  2. Install guides
  3. Server-rendered (Go, Node, PHP, Rails, Django)

Install the TermsBox Cookie Banner on a Server-Rendered Website

This guide is for websites where your server (Go, Node, PHP, Ruby, or Python) builds the HTML pages and sends them to the browser. If your site is built this way, almost every page shares one "base layout" or "master template". You only need to add the TermsBox snippet to that one shared file, and the banner will appear on every page automatically.

If you are not sure whether your site is server-rendered, look for a file that contains your site header, footer, and an <html> and <head> tag that all your pages reuse. That is your base layout.


What you need

  1. Your site id. This is a short code that tells TermsBox which website is loading the banner. It looks like a random string of letters and numbers.
  2. Where to get it: Log in to TermsBox, then go to Dashboard, Consent Banner, Install tab (the page at /dashboard/banner). Your site id is already filled into a ready-to-copy snippet there. You do not need to type the site id by hand: copy the whole snippet.

Tip: If you manage more than one website, make sure the correct site is selected in the dashboard before you copy. Each website has its own site id.


The snippet to copy

This is the exact code to add. Replace YOUR_SITE_KEY with your real site id (or just copy the pre-filled version from the dashboard, which already has your site id in it).

<script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>

Three important rules for this snippet:

  1. Put it inside the <head> section, not in the <body> or footer. It needs to run before your other scripts load.
  2. Do not add async or defer to the script tag. The banner must load in order, before your tracking and analytics scripts. Adding async or defer will break it.
  3. Keep the data-site-id value. If it is missing or empty, a banner may appear but it will not connect to your account and will not work correctly. There will be no error message, so it can look fine while doing nothing.

The data-auto-block="on" part tells TermsBox to automatically hold back tracking scripts until the visitor gives consent. Leave it as shown.


Where to place it, by platform

The idea is the same for every stack: find the one shared base layout that wraps all your pages, and paste the snippet inside its <head>. Pick your platform below.

Go (html/template)

Most Go sites define a base template with the shared <head>. Open that file (often named something like layout.html, base.html, or base.tmpl) and paste the snippet inside the <head>.

<head>
  <meta charset="utf-8">
  <title>{{ .Title }}</title>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

Every page template that uses this base layout will now include the banner.

Node / Express (EJS, Handlebars, or Pug)

Express apps usually have one layout file that other views extend or include. Add the snippet to the <head> of that layout.

EJS (for example views/layout.ejs):

<head>
  <title><%= title %></title>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

Handlebars (for example views/layouts/main.handlebars):

<head>
  <title>{{title}}</title>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

Pug (for example views/layout.pug). Because the snippet has no async or defer, you can drop in the raw HTML using a plain text block:

head
  title= title
  // Paste the raw script tag as plain HTML:
  script(src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on")

PHP / Laravel (Blade)

Laravel sites share one Blade layout, usually resources/views/layouts/app.blade.php. Add the snippet to its <head>.

<head>
  <title>@yield('title')</title>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

For plain PHP without Laravel, find the shared header file that every page includes (often header.php) and paste the snippet inside its <head>.

Ruby on Rails (application.html.erb)

Rails has one main layout at app/views/layouts/application.html.erb. Add the snippet to its <head>.

<head>
  <title>My Site</title>
  <%= csrf_meta_tags %>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

Note: place the plain <script> tag as shown. Do not use the Rails javascript_include_tag helper for this, because that helper can add defer automatically, which will break the banner.

Django or Flask (base template)

Both Django and Flask use a base template that all your pages extend, commonly templates/base.html. Add the snippet to its <head>.

<head>
  <title>{% block title %}My Site{% endblock %}</title>

  <script src="https://termsbox.com/cmp/termsbox-cmp.js" data-site-id="YOUR_SITE_KEY" data-auto-block="on"></script>
</head>

Every page that starts with {% extends "base.html" %} will now show the banner.


Verify it works

  1. Deploy or restart your site so the change goes live.
  2. Open your website in a browser and do a hard refresh (hold Shift and click reload) to avoid a cached page.
  3. Look for the cookie banner to appear, usually at the bottom or as a small box on screen.
  4. Confirm it on the correct address. TermsBox checks the main website address saved on your account, so make sure your live homepage has the snippet, not just one inner page.
  5. Use the dashboard button. Go back to Dashboard, Consent Banner, Install tab and click Verify Installation. TermsBox will fetch your homepage and confirm the snippet is present. On success the status changes to verified.

You can also open your page, right-click, choose "View page source", and search for termsbox-cmp.js. If you find it inside the <head>, the snippet is in place.


Troubleshooting

The banner does not appear.

  • Confirm the snippet is in the base layout that every page shares, not in a single page that you forgot to rebuild.
  • Confirm it is inside <head>, not in the body or footer.
  • Make sure you did not add async or defer. Remove them if present.
  • Do a hard refresh. Your browser or a caching layer (for example a CDN) may still be serving the old page.

The banner appears but nothing happens, or consent is not saved.

  • Check that data-site-id still has your real site id and is not empty. A dropped or blank site id shows a banner that does not actually work, with no error.
  • Make sure you copied the site id for the correct website if you manage more than one.

"Verify Installation" says it could not find the script.

  • The verifier checks your main saved site address (usually your homepage). Make sure the snippet is live on that address, not only on an inner page.
  • If your homepage is behind a login, a password, or strong bot protection, the verifier may be blocked from reading it. The banner can still be working for real visitors. Load the page yourself and check the source for termsbox-cmp.js to confirm.
  • Wait a moment and try again. There is a short limit of a few checks per minute.

I have more than one website.

  • Each website needs its own snippet with its own site id. Select the right site in the dashboard, copy that snippet, and install it on that specific site.
View install guides for all platforms
TermsBox

Scan your website, auto-generate legal documents, add a consent banner, and stay compliant. One platform for everything.

Product

  • Cookie Scanner
  • Consent Banner
  • Cookie Policy Generator
  • Pricing

Generators

  • Privacy Policy Generator
  • Terms and Conditions Generator
  • EULA Generator
  • Disclaimer Generator
  • Return and Refund Policy Generator

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service
  • Cookie Policy
GDPR
ePrivacy
CCPA
LGPD
Google Consent Mode v2
IAB TCF 2.2
© 2026 TermsBox. All rights reserved.