How to add Amabrik to Drupal
Add the Amabrik snippet to a Drupal 10 or 11 site with the Asset Injector module or your theme's html.html.twig head. Step-by-step guide, any theme.
Amabrik runs on your Drupal site from a single line of code. There’s no Amabrik module to install and nothing to maintain. You paste one <script> tag into your site’s <head>, and every widget you turn on in your dashboard shows up on your live site automatically.
This guide covers two ways to add that snippet on Drupal 10 and Drupal 11: the free Asset Injector module (the no-code path, and the one we recommend) and editing your theme’s html.html.twig head directly. Pick one. You don’t need both.
One thing to know up front: Drupal’s content blocks and text formats strip <script> tags out for security, so a plain “Custom HTML” block in the header region will not run the snippet. That’s why the no-code path below uses Asset Injector, which is built to output scripts safely. We explain the block route too, and why it falls short, so you don’t waste time on it.
1. Get your snippet
-
Sign in to your Amabrik dashboard at app.amabrik.com.
-
Open the Install page from the left menu.
-
Copy the snippet shown there. It looks like this, with your own site ID in place of
YOUR_SITE_ID:<script async src="https://cdn.amabrik.com/v1/loader.js" data-site="YOUR_SITE_ID"></script>
Always copy the snippet from your own dashboard so the data-site value is correct. The wrong ID means your widgets won’t load.
Method A: the Asset Injector module (recommended, no code)
Asset Injector lets a site administrator add a script to every page from the admin UI, with no theme editing. It works on Drupal 10.3 and Drupal 11, and because the snippet lives in configuration and not in your theme files, switching or updating your theme won’t remove it.
-
Download and enable the module. The fastest way is Composer: from your site root, run
composer require drupal/asset_injector. If you manage modules through the UI instead, download it from drupal.org/project/asset_injector and add it under Extend > Add new module. -
In your Drupal admin, go to Extend (the path is
/admin/modules), search for Asset Injector, tick JS Injector and CSS Injector (both ship inside the Asset Injector package), and click Install. -
Go to Configuration > Development > Asset Injector > JS Injector (the path is
/admin/config/development/asset-injector/js). -
Click Add JS injector.
-
Give it a clear label, for example
Amabrik loader. -
In the Code field, paste only the part inside the script tag, as a small loader that adds Amabrik for you:
(function () { var s = document.createElement('script'); s.async = true; s.src = 'https://cdn.amabrik.com/v1/loader.js'; s.setAttribute('data-site', 'YOUR_SITE_ID'); document.head.appendChild(s); })();Replace
YOUR_SITE_IDwith the ID from your dashboard. Asset Injector’s JS field expects JavaScript, not a raw<script src="...">tag, so this small loader is the reliable way to pull in the Amabrik snippet. -
Leave Conditions empty so the loader runs on every page (that’s what you want for site-wide widgets).
-
Click Save.
Asset Injector now adds Amabrik to every page for you. Skip to step 2 below to confirm it’s live.
Why a plain “Custom HTML” block does not work here
You might expect to create a content block of type Basic block / Custom HTML, paste the snippet, set the text format to Full HTML, and place it in a header region under Structure > Block layout (/admin/structure/block). The block UI even shows a Demonstrate block regions link and a Place block button per region, so it looks like the right tool.
It is not, for the snippet. Even with the Full HTML text format, Drupal’s filter system removes <script> tags from block body content before the page renders, so the loader never runs. A header block is great for visible markup like a notice or a logo, but not for an external script. Use Method A (Asset Injector) or Method B (the theme head) instead.
Method B: your theme’s html.html.twig head (for developers)
Use this if you maintain your own theme and would rather keep the snippet in code. This puts the tag directly into the document <head>, which is exactly where Amabrik wants it.
-
In your theme folder (for a custom theme,
themes/custom/YOUR_THEME/), findtemplates/html.html.twig. If your theme doesn’t have one, copy Drupal core’s version fromcore/modules/system/templates/html.html.twiginto your theme’stemplates/folder. Drupal will then use your copy. -
Open
html.html.twig. You’ll see the<head>block with{{ head }}and a<css-placeholder>line inside it. -
Add your Amabrik snippet inside the
<head>, for example right after{{ head }}:<head> <meta charset="utf-8" /> {{ head }} <script async src="https://cdn.amabrik.com/v1/loader.js" data-site="YOUR_SITE_ID"></script> <css-placeholder token="{{ placeholder_token }}"> <js-placeholder token="{{ placeholder_token }}"> </head>Keep the
<css-placeholder>and<js-placeholder>lines as they are. ReplaceYOUR_SITE_IDwith the ID from your dashboard. -
Save the file.
A cleaner, fully Drupal-native variant is to define the loader in your theme’s *.libraries.yml with header: true and attach it with {{ attach_library('YOUR_THEME/amabrik') }}. Both approaches put the script in the head. The inline template edit above is the most direct, so we show it first.
Whichever way you go, clear the cache next.
2. Save and clear the cache
Drupal caches rendered pages and template output, so a new snippet won’t appear until you clear the cache.
- In your admin, go to Configuration > Development > Performance (
/admin/config/development/performance) and click Clear all caches. - Or, if you use the command line, run
drush crfrom your site root.
Do this after Method A or Method B. Without it, you’ll keep seeing the old, cached page.
3. Check it’s live
Confirm the snippet is actually on your site:
- Open your site’s home page in a normal browser tab.
- Right-click anywhere and choose View Page Source (or press Ctrl+U on Windows, Cmd+Option+U on a Mac).
- Use Find (Ctrl+F or Cmd+F) and search for
amabrik. - You should see a reference to
cdn.amabrik.com/v1/loader.jswith your site ID.
With Method A, the loader is added by JavaScript, so it appears once the page runs. If View Page Source doesn’t show it, open your browser’s developer tools, go to the Network tab, reload, and filter for amabrik. You should see loader.js load.
If you find it, the install worked.
4. Turn on widgets in the dashboard
The snippet is the connection. Your widgets are controlled entirely from Amabrik, so you never touch your Drupal site again.
- Back in your Amabrik dashboard, open Widgets.
- Create or enable the widgets you want (banner, cookie consent, popup, forms, and so on).
- Publish. Changes go live on your site within seconds, with no Drupal edit needed.
From here, every future change happens in Amabrik. Your Drupal site already has everything it needs.
Troubleshooting
I pasted the snippet into a content block and nothing runs. Drupal strips <script> tags from block body content, even with the Full HTML text format, so the loader never executes. This is the most common Drupal mistake. Use Method A (Asset Injector) or Method B (the theme head) instead.
My text format stripped the script. Same cause as above. Text formats apply filters that remove script tags by design. There’s no safe text-format setting that keeps an external script in a block. Move the snippet to Asset Injector or the theme head.
I made the change but still see the old page. Clear the Drupal cache (Configuration > Development > Performance > Clear all caches, or drush cr), then reload in a private or incognito window so your browser doesn’t serve a cached copy. A reverse proxy or CDN in front of Drupal (Varnish, Cloudflare) may need its cache cleared too.
I added a header block but it doesn’t appear. Check the region. Under Structure > Block layout, use Demonstrate block regions to see where each region actually shows in your theme, then confirm your block sits in the region you expect. Note that this only matters for visible content blocks, not the Amabrik snippet, which belongs in Method A or B.
The widget loads but shows nothing. Make sure the widget is published in your Amabrik dashboard and that your site’s domain matches the domain set in Amabrik. Amabrik only serves your config to your own domain, so a mismatch blocks it.
FAQ
Is there an Amabrik module for Drupal?
No. Amabrik is one script tag, so there’s nothing to install or update on Drupal itself. Asset Injector is just a convenient way to place that tag without editing your theme.
Why can’t I just use a Custom HTML block in the header?
Drupal removes <script> tags from block content for security, so the loader won’t run from a block. That’s not an Amabrik limit, it’s how Drupal’s text formats work. Asset Injector and the theme head are the supported ways to add an external script.
Will this slow down my site?
The snippet uses the async attribute, so it loads without blocking your page. The browser keeps rendering while the script downloads in the background.
Does this work on Drupal 10 and Drupal 11?
Yes. The Asset Injector module supports Drupal 10.3 and Drupal 11, and the html.html.twig head edit works the same way on both.
Can I remove Amabrik later?
Yes. Delete the Asset Injector entry (or remove the line from html.html.twig), clear the cache, and Amabrik is gone. No leftovers.
Last updated June 22, 2026
Want us to install it for you?
Open the Install page in your dashboard and use the Request Installation tab. Our team sets it up for you.