Help centerRoutes, headers & scripts
Injected scripts and HTML
Insert scripts, styles and tags (chat, widgets, CSS, meta tags) into the head or the end of the body of every page, project-wide or for a single domain.
With HTML injection you can put any snippet of code on every page of the customer's domain: a chat widget, a style that hides something in the app, a verification meta tag. Nothing changes in the origin's code, and each domain can have its own.
How it works
Each injection has some HTML code and a place, under Where to insert:
| Option | Where it goes | Good for |
|---|---|---|
In the <head> |
At the end of the page's <head> |
<style>, <meta>, <link>, scripts that must load early |
At the end of the <body> |
Right before </body> |
Chat widgets, scripts that work on the loaded page |
- The code goes into every HTML page your app serves through the domain. JS, CSS, JSON and image files are left untouched;
- several injections in the same place go in list order (use the arrows to reorder);
- the code is inserted exactly as you wrote it: nothing is validated or "fixed";
- it works with the HTML cache: injections are applied on every visit, with the current version.
Adding an injection
- Open the project and go to the Customization tab;
- On the HTML injection tab, click Add injection;
- Under Where to insert, choose In the
<head>or At the end of the<body>; - Paste the code into HTML code (with its tags:
<script>...</script>,<style>...</style>); - Click Add injection. The code shows up on the pages within seconds.
In the list, each injection is collapsed to the first line of its code. Click Edit code to open it, change it and click Save. The switch pauses an injection without deleting it.
Marketing scripts and customer data
- For Google Analytics, Tag Manager, Meta Pixel, TikTok and similar, prefer marketing tags: they respect the cookie banner (LGPD/Consent Mode) and aren't sent to bots. An injection always loads, for every visitor;
- does your script need to know who the domain's customer is (name, plan, id)? Use the
tenant context, which can expose that data in
window.TENANCI.
Limits: up to 256 KB per injection and up to 50 injections per domain.
Project and domain
Project injections apply to every domain. For a domain to have its own, open the domain's Customization tab and turn on the switch in the HTML injection card (Own configuration): from then on the domain uses only its own injections (it starts with a copy of the project's; later project changes no longer reach it). Details in Routes.
Via the API
Same operations as routes, with injections instead of routes:
POST /projects/:id/rules/injections,
POST /domains/:id/rules/injections,
PATCH /rules/injections/:ruleId and
DELETE /rules/injections/:ruleId. The body has content (the code) and
injectAt (head, the default, or body).
curl -X POST https://api.tenanci.com/v2/domains/dom_4h7n1q/rules/injections \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"injectAt":"body","content":"<script src=\"https://chat.example.com/widget.js\" async></script>"}'await tenanci.request("POST", "/domains/dom_4h7n1q/rules/injections", {
injectAt: "body",
content: '<script src="https://chat.example.com/widget.js" async></script>',
});
