All components · Category: Banners and notices
Offer modal
An offer dialog that opens only when the visitor asks for it.
A real modal dialog: focus moves in, Tab stays inside, Escape or a click on the backdrop closes it and focus goes back to the button. It never opens on load, on a timer or on exit intent, and it can cover just its own box or the whole page.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<modal-offer href="https://example.com/book" locale="en"></modal-offer>
<script>
const element = document.querySelector("modal-offer");
element.addEventListener("modal-offer:opened", (event) => {
console.log(event.detail);
});
element.addEventListener("modal-offer:closed", (event) => {
console.log(event.detail);
});
</script>
- Add the site's Taggor script once; the component appears when it loads.
taggor-component.js
const element = document.createElement("modal-offer");
element.setAttribute("href", "https://example.com/book");
element.setAttribute("locale", "en");
element.addEventListener("modal-offer:opened", (event) => {
console.log(event.detail);
});
element.addEventListener("modal-offer:closed", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
ModalOffer.tsx
import { useEffect, useRef } from "react";
export function ModalOffer() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onOpened = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("modal-offer:opened", onOpened);
const onClosed = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("modal-offer:closed", onClosed);
return () => {
element.removeEventListener("modal-offer:opened", onOpened);
element.removeEventListener("modal-offer:closed", onClosed);
};
}, []);
return <modal-offer ref={ref} href="https://example.com/book" locale="en" />;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 18 sends every prop of a custom element as a text attribute.
- The event is heard with addEventListener, inside an effect.
ModalOffer.tsx
import { useEffect, useRef } from "react";
export function ModalOffer() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onOpened = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("modal-offer:opened", onOpened);
const onClosed = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("modal-offer:closed", onClosed);
return () => {
element.removeEventListener("modal-offer:opened", onOpened);
element.removeEventListener("modal-offer:closed", onClosed);
};
}, []);
return <modal-offer ref={ref} href="https://example.com/book" locale="en" />;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 19 sets a property when the element already has it, an attribute otherwise.
- The event is heard with addEventListener, inside an effect.
src/ModalOffer.vue
<script setup lang="ts">
function onOpened(event: Event) {
console.log((event as CustomEvent).detail);
}
function onClosed(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<modal-offer
href="https://example.com/book"
locale="en"
@modal-offer:opened="onOpened"
@modal-offer:closed="onClosed"
/>
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "modal-offer",
},
},
}),
],
});
- Add the site's Taggor script once; the component appears when it loads.
- vite.config.ts tells Vue that this tag is not a Vue component.
src/app/modal-offer.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-modal-offer",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<modal-offer href="https://example.com/book" locale="en"></modal-offer>
`,
})
export class ModalOfferComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("modal-offer");
const onOpened = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("modal-offer:opened", onOpened));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("modal-offer:opened", onOpened));
const onClosed = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("modal-offer:closed", onClosed));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("modal-offer:closed", onClosed));
}
}
- Add the site's Taggor script once; the component appears when it loads.
- The component declares CUSTOM_ELEMENTS_SCHEMA.
- The event is heard with addEventListener, inside an effect.
src/TaggorComponent.svelte
<script>
function onOpened(event) {
console.log(event.detail);
}
function onClosed(event) {
console.log(event.detail);
}
</script>
<modal-offer
href="https://example.com/book"
locale="en"
onmodal-offer:opened={onOpened}
onmodal-offer:closed={onClosed}
></modal-offer>
- Add the site's Taggor script once; the component appears when it loads.
How an agent gets a component like this onto a site:
taggor checktaggor publishThe CSS variables the component exposes, set the way a customer's page would.
styles.css
modal-offer {
--mo-radius: 20px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| heading | string | none | Replaces the dialog heading. |
| body | string | none | Replaces the dialog text. |
| cta | string | none | Replaces the offer button text. |
| href | url | none | Where the offer button goes; without it the button only closes. |
| triggerLabel | string | none | Replaces the text of the opening button. |
| scope | box | page | box | box covers this component; page covers the host page. |
| hideSample | boolean | false | Hides the Sample content mark. |
| locale | pt-BR | en | en | – |
Prop names and descriptions are the component's own, in English, as its author wrote them.
03
Events
| Event | When it fires |
|---|---|
| opened | The visitor opened the offer. |
| closed | The offer was closed. |
04
Build one with your agent
Paste this into your agent. It asks you before it signs in, pays or goes further than checking and publishing.
Build me a Taggor component like "Offer modal" (modal-offer): An offer dialog that opens only when the visitor asks for it.
Fetch https://taggor.dev/agent-setup/prompt.md and follow its instructions to set me up for Taggor. Ask me before you sign in, create an account, accept terms, pay for anything or type a secret.
Check it with `taggor check` and publish it with `taggor publish`, and stop there.
Do not promote it to production, attach it to a site, roll back anything or use --yes, --force or --force-drop-invalid unless I ask for exactly that in this conversation.
05
Related components
- Announcement bar<announcement-bar>
- Toast stack<toast-stack>
- Lead form<contact-form>