Repository navigation
feat: customer segments and campaigns - #105
Merged
Merged
Conversation
…campaigns # Conflicts: # server/src/routes.php
Customer segments are rule based audiences of a store's or network's customers (order count bounds, ordered or lapsed within N days, joined within N days, minimum spend, reachable by push, explicit customers). Campaigns send a title/body with an optional image and deep link to a segment (or explicit recipients, or everyone) by push and/or inbox, now or at a scheduled time. storefront:dispatch-campaigns claims due campaigns atomically and queues delivery in batches; customers who turned promotions off are skipped. Promotions can be announced with a campaign that goes out when the promotion starts, and announcements for promotions that stopped running are canceled. The console API manages segments (with live audience previews) and campaigns (send now, cancel, audience count). The existing promotional push action now sends a tracked campaign.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v0.4.22 #105 +/- ##
=====================================================
Coverage 100.00% 100.00%
- Complexity 1772 2281 +509
=====================================================
Files 135 182 +47
Lines 7778 9070 +1292
=====================================================
+ Hits 7778 9070 +1292
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Sep 27, 2026
Merged
roncodes
marked this pull request as ready for review
September 28, 2026 04:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds customer segments and campaigns, so stores and networks can send targeted notifications to their customers (push and/or the in-app inbox) now or on a schedule, and announce promotions automatically.
Segments (
customer_segments)Rule-based audiences of a store's or network's customers. All rules are optional and combined with AND. Order rules count the customer's non-canceled storefront orders placed with the owning store or network.
customersmin_orders/max_ordersmax_orders: 0means never ordered here)ordered_within_daysnot_ordered_within_daysjoined_within_daysmin_spenthas_push_deviceCampaigns (
campaigns)action(promotion,product,store,categoryorurl).pushand/orinbox.recipients, both (intersected), or all customers.draft→scheduled(send_at) →sending→sent, orcanceled.storefront:dispatch-campaignsruns every minute. It claims due campaigns atomically (never sent twice), resolves the audience, and queuesSendCampaignBatchjobs of 250 customers.statsrecordstargetedandbatches.Promotions trigger notifications
POST int/v1/promotions/{id}/announce(optionaltitle,body,segment,channels,send_at) creates a campaign that deep links to the promotion and uses its image. It goes out when the promotion starts, or immediately if the promotion has already started.Console API (
storefront/int/v1)customer-segmentsGET {id}/previewandPOST preview(owner_uuid,rules) return{ count, sample[10] }for a live segment buildercampaignsPOST {id}/send(send now),POST {id}/cancel,GET {id}/audience({ count })promotions/{id}/announcePermissions: new
customer-segment(preview) andcampaign(send,cancel) resources, plusannounceonpromotion. ThePromotionsManagerpolicy covers all of them.Existing endpoint:
POST int/v1/actions/send-push-notification(the console's current "push notification" screen) now creates and sends a campaign. That means it's recorded, respects preferences, goes to the inbox too, and is delivered in queued batches. The response keepsstatus,sent_countandtotal(now the number targeted) and addscampaign.PromotionalPushNotificationis no longer used internally and is marked@deprecated.Related Issue
Part of the promotions / notifications work. No tracking issue.
Type of Change
Implementation Notes
Promotions/SegmentResolver(rules to aContactquery),Promotions/CampaignDispatcher(claim, audience, batching),Jobs/SendCampaignBatch,Notifications/CampaignNotification(push through the fix: rebuild push notifications on a single storefront push channel #102 channel; inbox and realtime through feat: customer notifications inbox API #103).2026_09_27_100000_create_customer_segments_and_campaigns_tables.Validation
New:
server/tests/Unit/Promotions/CampaignDeliveryTest.php(every segment rule, network segments, due dispatching and batching, claim idempotency, recipient narrowing with an empty list reaching nobody, cancellation reasons, batch failure isolation, the command, the notification's channels, preferences, payload and storefronts) andCampaignEndpointsTest.php(send, cancel, audience, segment previews, announce, validation, filters, resources, the reworked push action).Documentation Impact
fleetbase/fleetbase.ioAPI Reference Impact
fleetbase/postmanAPI reference notes: these are console (internal) endpoints only; there are no public API changes. The
send-push-notificationresponse addscampaign.Documentation Notes
fleetbase.io, Storefront → Promotions → Segments and campaigns (rules, scheduling, announcing promotions, preferences).
Risk
SendCampaignBatch), so a queue worker must run. With thesyncdriver it sends inline as before.storefront:dispatch-campaignsevery minute).min_spentsums storefront transactions across the whole company, not per store.