supabase_in_app_messaging 0.1.0
supabase_in_app_messaging: ^0.1.0 copied to clipboard
In-app messaging for Flutter on Supabase: campaigns in Postgres, shown as a banner, modal or card on app events, with frequency caps.
In-app messaging for Flutter, kept in your Supabase Postgres: campaigns chosen on the server for each user, shown inside the running app as a banner, modal or card that follows your theme.
flutter pub add supabase_in_app_messaging
Firebase In-App Messaging's model — campaigns with an audience, a schedule and trigger events — in the database you already run, with no Firebase project next to Supabase, and messages drawn by Flutter, not by a native SDK.
Quick start · Triggers · Campaigns · Widgets · Security · FAQ · Documentation · Changelog
Features #
- Campaigns in your own Postgres — one table, edited in Supabase Studio or with SQL. They are in your backups, they ship in a migration, and you query them like the rest of your data.
- Chosen on the server — the app makes one call,
iam_campaigns_for(context), and gets back only the campaigns meant for it, highest priority first. The audience never reaches the device. - Shown on your events —
trigger('purchase_done')shows the highest-priority campaign for it, andapp_openfires by itself on launch and resume. One message at a time, none on screens you suppress, and a veto for the ones you don't want. - Audience, schedule and priority — everyone, signed-in users or a list of users; platforms; an app version range, for "please update"; a start and an end; a switch that is off until you turn it on.
- Frequency caps — at most N impressions per user, a minimum time between two, or never again after a click. Counted on the server across devices, and on the device when offline or signed out.
- Works offline — the campaigns last fetched are cached on the device, so
a launch without a network still shows the
app_openone, and events wait in a queue until they can be sent. - Metrics in SQL — impressions, clicks, click-through rate, dismissals and
unique users per campaign and day, in the
iam_campaign_statsview. - Translated — a campaign's title, body and buttons per locale; the server sends each device only the text for its language.
- Live updates — pause, edit or add a campaign and running apps fetch again within seconds, over a private Realtime channel that carries only an empty signal.
- Banner, modal or card — Flutter widgets that follow your
Theme, with a builder to replace any layout and keep the rest. - Accessible — announced to screen readers, dismissed by back as well as by swipe, scrolling at large text sizes, inside the safe area, readable on tablets.
- Locked down — row level security on with no policies; two functions are all a client can call, and invalid campaigns are rejected when you save them.
- Testable —
FakeInAppMessagingshows messages from a list in memory and records what was shown and tapped, for widget tests without Supabase.
Quick start #
flutter pub add supabase_in_app_messaging
In the database #
Run
supabase/in_app_messaging.sql
once per Supabase project, in the SQL editor or as a migration
(how).
It is re-runnable. Then add a campaign:
insert into iam_campaigns (layout, title, body, buttons, active)
values (
'card',
'Summer sale',
'Everything 20% off this week.',
'[{"text": "Shop now", "action": "url", "url": "myapp://store"},
{"text": "Not now", "action": "dismiss"}]',
true
);
In the app #
final navigatorKey = GlobalKey<NavigatorState>();
final messaging = await InAppMessaging.initialize(
Supabase.instance.client,
appVersion: '1.4.0', // from package_info_plus or your build config
navigatorKey: navigatorKey,
onUrl: (url) => launchUrl(Uri.parse(url)), // url_launcher, or your router
);
runApp(MaterialApp(navigatorKey: navigatorKey, home: const HomePage()));
That is the whole setup. The client fetches the campaigns meant for this user
and shows the app_open one; fetches again when someone signs in or out; and
shows a campaign when the app fires one of its events:
messaging.trigger('purchase_done');
In tests, pass a FakeInAppMessaging from
package:supabase_in_app_messaging/testing.dart
(testing).
A runnable app that shows all three layouts is in
example/.
Why supabase_in_app_messaging? #
Telling users something inside the app — a sale, a new feature, a "please
update" — at the right moment, to the right people, without shipping a
release, needs the messages to live outside the app. In an app whose backend
is Supabase, the usual answer is a Firebase project and its SDK next to it,
plus Google Analytics for audiences and events, only to show a card.
supabase_in_app_messaging keeps the model in the Postgres you already run.
| Without it | What supabase_in_app_messaging adds |
|
|---|---|---|
| An announcements table the app reads | Every client downloads every row, audience included, and filters on the device | Postgres picks the campaigns; each client sees only its own |
| Firebase In-App Messaging | A second backend, its console and SDK, and Google Analytics beside Supabase; native templates unless you draw and report each message yourself; Android and iOS only | The same model in your database, edited in Studio, drawn by Flutter widgets you can replace, on every Flutter platform |
| A dialog coded into the app | A store release to change the text or stop showing it | A row update, picked up on the next fetch |
When something else is enough #
| You want | Enough on its own | supabase_in_app_messaging adds |
|---|---|---|
| One announcement, once | showDialog and a flag in shared_preferences |
An audience, a schedule, priorities, and no release to change it |
| In-app messages in an app that already runs on Firebase | firebase_in_app_messaging |
The campaigns in your Postgres, next to your data, in your theme |
| Push notifications | supabase_realtime_push, or FCM |
Messages inside the running app, not in the notification tray |
Triggers #
messaging.trigger('purchase_done'); // the first campaign for the event, by priority
messaging.messagesSuppressed = true; // checkout, a video: nothing shows
app_open fires by itself after the first fetch and each time the app comes
back from the background. A trigger while a message is on screen, or while
messages are suppressed, is dropped, not queued. shouldShow: in initialize
vetoes a campaign — an upgrade offer to someone who already upgraded — and the
next one for the event is offered. Triggers are event names: for "on the third
launch", count in the app and fire trigger('third_launch').
→ The client API
Campaigns #
A campaign is a row: what to show, who sees it, and when.
-- Only signed-in Android users on 2.10.0 or later, for December.
insert into iam_campaigns
(layout, title, body, audience, platforms, min_app_version, starts_at, ends_at, priority, active)
values
('banner', 'Dark mode is here', 'Turn it on in Settings.', 'signed_in',
'{android}', '2.10.0', '2026-12-01', '2027-01-01', 10, true);
-- What a signed-in Android app on 2.10.0 gets. In the SQL editor nobody is
-- signed in, so this campaign is left out there.
select iam_campaigns_for('{"platform": "android", "app_version": "2.10.0"}');
-- [{"id": "…", "layout": "banner", "title": "Dark mode is here", …}]
| Column | Picks |
|---|---|
audience, user_ids |
everyone, signed_in, or the users in user_ids — read from the JWT |
platforms |
android, ios, web, macos, windows, linux; null is all |
min_app_version, max_app_version |
major.minor.patch, compared as numbers (2.10.0 is after 2.9.0); the maximum is exclusive, for "please update" |
starts_at, ends_at, active |
When it runs, and the switch, off by default |
priority |
Higher shows first |
trigger_events |
The app events that may show it; app_open by default |
translations |
The title, body and button texts per locale, picked from the device's |
max_impressions, min_interval, stop_after_click |
How often one user sees it: at most N times, at least this long apart, or never after a click |
A check constraint keeps every campaign showable — a known layout, a title, at most two well-formed buttons — so a typo is caught when you save it, not on the device. → Every column, and what the app receives
Widgets #
final tapped = await showInAppMessage(context, message, onUrl: openUrl);
| Layout | Where | Dismissed by |
|---|---|---|
banner |
A strip at the top, the screen under it not dimmed | Swiping up, back, a tap outside |
modal |
A dialog in the middle | Back, a tap outside |
card |
A card at the bottom | Swiping down, back, a tap outside |
Colors, shapes and text come from your Theme (CardTheme, DialogTheme,
TextTheme, TextButtonTheme). builder: replaces the content of any layout,
and the position, safe area, dismissal and screen-reader announcement stay:
showInAppMessage(
context,
message,
builder: (context, message, close) =>
message.layout == InAppMessageLayout.banner
? MyBanner(message, onTap: () => close(message.buttons.firstOrNull))
: null, // null keeps the default for this message
);
→ Layouts, theming, the builder and accessibility
Security #
- Clients cannot read or write
iam_campaigns: row level security is on with no policies, andanonandauthenticatedhave no privileges on it. - They can call
iam_campaigns_for, asecurity definerfunction that returns the campaigns meant for them, and, when signed in,iam_track, which records what they were shown as their ownauth.uid(), at most 300 events an hour. Nothing else: they cannot read the events back, or theiam_campaign_statsmetrics. - Who the user is comes from the JWT, so a campaign for a list of users reaches only them.
- Platform and app version are claimed by the client. They decide who is shown a campaign; they do not hide it. Treat every campaign that is not for a list of users as public.
Supabase's Security Advisor flags iam_campaigns_for as a security definer
function anon and authenticated can execute, and iam_track as one
authenticated can execute. That is expected: they are the only way in.
→ Security model
Documentation #
| Getting started | Installing, running the SQL in the SQL editor or as a migration, the first campaign on screen |
| Frequency caps | max_impressions, min_interval, stop_after_click, where they are counted, iam_events |
| Offline | What the device caches per project and user, the event queue, an offline launch |
| Metrics | iam_campaign_stats, iam_track's limits, pruning old events |
| The client API | initialize, fetching, live updates, triggers, app_open, suppressing and vetoing messages, testing with FakeInAppMessaging |
| Campaigns | Every column, the audience, schedule and priority, buttons, trigger events, translations, what the app receives |
| Recipes | An onboarding tip, a rating prompt, a new feature announcement and an update prompt, as SQL and Dart to copy |
| Widgets | tryParse, showInAppMessage, the three layouts, theming, the builder, accessibility |
| Security model | What clients can and cannot do, the claimed context, the Realtime signal, service_role |
| Coming from Firebase In-App Messaging | The API and the console side by side, layouts, caps, targeting, analytics, how to switch |
With an AI assistant: point the agent at
llms.txt,
an index of these pages, so it answers from the current API instead of
guessing. The docs are also on
Context7, as
/franklyn-r-silva/supabase_in_app_messaging, for agents that use its MCP server.
Coming from Firebase In-App Messaging #
triggerEvent becomes trigger, and setMessagesSuppressed the
messagesSuppressed property. Campaigns move from the Firebase console to
rows of iam_campaigns, with the card, modal and banner layouts; the
image-only one has no equivalent. Firebase's per-device frequency limit
becomes caps per user and per device, which are off until you set them.
Audiences are signed-in users or lists of users instead of Analytics
audiences, and impressions, clicks and dismissals land in iam_events, in
your database, summed per day by the iam_campaign_stats view.
→ The API side by side, and how to switch
FAQ #
Do I need supabase_flutter? #
No. initialize takes a SupabaseClient from
supabase, the pure Dart client. In a
supabase_flutter app, Supabase.instance.client is that same class, so pass
it as it is.
I added a campaign and the app does not show it #
iam_campaigns_for returns only what is showable right now. Check, in order:
active is true (it is off by default); starts_at has passed and ends_at
has not; the audience matches (signed_in needs a session); the platform is
in platforms; the app version is inside min_app_version and
max_app_version; and the app fires one of the campaign's trigger_events —
app_open fires by itself; and the user has not
reached its frequency cap. The client fetches on launch, on sign-in or
sign-out, when the app is shown again, and within seconds of a change to
iam_campaigns where Realtime is enabled; without Realtime, a campaign added
while the app runs shows after the next launch or return to the app.
Can users read other users' campaigns, or the audience? #
No. The only campaigns clients get are what iam_campaigns_for returns: it
reads the user from the JWT and returns the fields a message needs, never
user_ids, platforms or versions. They can claim any platform or app version,
which reveals the campaigns targeted at it — so never put anything private in a
campaign that is not for a list of users.
Can I use my own design? #
Yes: builder replaces the content of any layout, per message, and returning
null keeps the default. Position, dismissal and accessibility stay.
How does a button open a link? #
A url button closes the message and hands its url to onUrl. The package
opens nothing itself — call url_launcher, or your router for a deep link.
Where do images come from? #
Any http:// or https:// URL, such as a public Supabase Storage bucket's.
An image that fails to load is left out and the message is shown without it.
Can a message be only an image? #
Not as a layout: every campaign has a title, which names the message for
screen readers, so Firebase's image-only layout has no equivalent. A modal
with an image_url and a short title comes closest, or a builder that draws
only the image.
How many people saw a campaign? #
iam_campaign_stats has impressions, clicks, click-through rate, dismissals
and unique users per campaign and day, from the events of signed-in users;
signed-out users send nothing. Read it in the SQL editor.
→ Metrics
Is there an admin UI? #
Supabase Studio is the editor: the Table Editor for rows, the SQL editor for anything else.
Does it send push notifications? #
No. In-app messages show inside the running app. For notifications, see
supabase_realtime_push.
Which Flutter versions does it support? #
Flutter 3.32 and newer, on Android, iOS, web, Windows, macOS and Linux: the messages are plain Flutter widgets.
Roadmap #
0.1.0 ships everything in the plan. What comes next is tracked in the issues.
Contributing #
Pull requests are welcome — see CONTRIBUTING.md for the dev
setup, the Dart and SQL tests and the commit format.
Start with a
good first issue;
questions go to
issues.
Code of Conduct · Security Policy ·
Changelog
License #
MIT © Franklyn R. Silva