show() presents for that placement, with the same premium brand offers, each one a real perk a brand funds to acquire customers.
Its trigger ID is giftsButton. Everything on Trigger components applies to it. This page covers only what is specific to Gifts Button.
Requires SDK 2.4.0+ on every platform. See Minimum SDK versions.
When to use it
Use Gifts Button on the screen where you would otherwise callshow() for a reward, for example the screen that celebrates a finished streak. Mount it there in place of your own show() call for that moment, not as well as it. Keeping both can present the sheet twice.
Its use case defaults to the reward use case, so leave useCase out. Churn isn’t supported yet: with the churn use case, Gifts Button renders nothing.
What the user sees
- An entry, only when there’s a gift. Gifts Button checks for offers for its use case and placement, the same check
show()makes before it presents. With no offers, it renders nothing. If you draw your own button, it must hide too: see Show your entry only when there are offers. - A tap opens the reward sheet. The sheet is the normal one for that use case and placement, as if your app had presented it.
- It stays while offers remain. When the sheet closes, Gifts Button checks again and hides only when no offers are left. The user can’t dismiss it.
- It may open the sheet once by itself. When an Encore test calls for it, Gifts Button can open its sheet on its own: at most once a day at each placement, only while your app is in the foreground, and never over another Encore sheet. It also waits while your app has the gift locked. Set
autoOpento off to stop it.
Place it in your layout
Use theGiftsButton shorthand for your platform. Give it a placement ID and, optionally, your appearance, which colors the entry and never the sheet it opens. Encore picks the look:
Each shorthand is the trigger host with the ID
giftsButton. The parameters table gives every default.
The moment
From SDK 2.7.0 (on Flutter and React Native, the release that requires native 2.7.0), Gifts Button takes amoment: why it shows now, so Encore learns which offers fit. See Add the moment.
Your text
Passheadline, subheadline and cta to put your own words on the entry, such as the name of the moment the user just reached:
cta only when it draws a button or a label, as banner and pill do. See Your text for the rules on length and line breaks.
Looks
Encore picks the look, and can test several against each other. These are the looks it serves today. It draws each one from a look file it can change without an app update, so treat the heights as defaults rather than constants.
Heights are in points on iOS,
dp on Android, and CSS pixels on the web. Each look is one control, named for assistive technology by its copy. The pulse animation and the scrolling logos of offerMarquee and offerColumns pause while the entry is off screen and stay still when the user has reduced motion turned on.
Pass your prize and read the result
When your app pays its own prize for trying an offer, pass it to Gifts Button aspublisherReward. It is the same value you would pass to placement(id).publisherReward(...) before show(), with the same rules: a PublisherReward on iOS, Android, and React Native, and an EncorePublisherReward on Flutter. On the web it is a PublisherReward with the same fields: id, title, and the optional detail and iconUrl. Gifts Button hands it to every sheet it opens. Pass onResult to receive the result of each sheet Gifts Button opens. It is called once per sheet, after the sheet closes, with the same result show() returns. Both are optional; without them Gifts Button behaves exactly as described earlier on this page.
On iOS, Android, React Native, and Flutter, grant the prize from onResult only, when userConfirmedCompletion is true on the result’s claim, with this grant key: the transaction ID, or your user ID plus campaignId when it is missing.
Other ways to learn about a claim
onResult is the main path, because it belongs to this one entry. Two other channels see the same claims:
- The outcomes stream. Every sheet Gifts Button opens resolves onto the same stream as your own
show()calls:Encore.shared.outcomeson iOS,Encore.outcomeson Android,Encore.shared.outcomeson Flutter,Encore.onOutcome()on React Native, andEncore.Outcomeson Unity. If your app already watches it, for analytics or entitlement sync, it sees Gifts Button’s claims with no extra code. On the web,onStrictUnlockVerified()reports a claim the brand later confirms, in strict unlock mode. - The
offer_completedwebhook. Your server hears about a completion the brand confirms, whichever surface the claim came from. See Receive completion events.
onResult receives, so an app that grants from both pays twice.
publisherReward on a mounted Gifts Button applies to the next sheet it opens.
Host state
Sometimes the gift should unlock only after the user does something in your app, such as reaching a goal. Only your app knows when that happens, so your app passes it to the Gifts Button as a host state. A host state has a status and, while locked, an optional progress:
Pass the progress smoothly, as a fraction from 0 to 1, or as steps, such as 3 of 4. Steps become completed divided by total, so 3 of 4 is the same as a progress of 0.75, and a total of 0 or less means no progress. Either way,
progress is clamped to 0 to 1, and a value that isn’t a finite number counts as no progress. The look decides how its ring draws the progress: as a smooth fill, or in whole segments. A look that fills whole segments uses its own segment count, not your total. If you pass steps and want the ring to show exactly that many pieces, ask your Encore contact to set the tile’s segment count to your total. Set the host state when you place the Gifts Button and change it whenever your app’s state changes:
.locked(progress:) or .locked(completed:of:), .ready and .done on iOS, and GiftsButtonHostState.locked(progress) or GiftsButtonHostState.locked(completed, total), GiftsButtonHostState.Ready and GiftsButtonHostState.Done on Android. progress is optional on both. Set the host state to nil or null, or leave it out, and the Gifts Button behaves exactly as the rest of this page describes.
What a host state changes:
- A locked tap opens nothing. Whatever the look draws, a tap while locked never opens the sheet and sends no click event, so taps that opened nothing never count as taps. The look can answer the tap with a short hint, such as a nudge of its ring.
- No opening by itself while locked. A look that opens the sheet once by itself waits while the status is locked. Once the status is ready or done, the usual once-a-day rule applies.
- It stays on the device. The host state is never sent in a request or stored. Changing it redraws the entry in place, with no new request. Only the status word (
locked,readyordone) goes on the entry’s analytics events, and only while you set a host state. The progress never leaves the device. - A new status is a new impression. Going from locked to ready counts a new impression with the new status. A progress change doesn’t.
Draw your own view when the button shows nothing
PassonShowingChange to learn whether the Gifts Button is drawing a look. It is called on the main thread with true while a look shows and false while the entry draws nothing, for example because there are no offers or the user is in a holdout group. It is called once the Gifts Button first has an answer for the user, then on each change.
Use it to draw your own view in the same spot when Encore draws nothing. Keep the Gifts Button mounted, since an empty one takes no space, and show your own view until it answers: it isn’t called before configure(), so a Gifts Button that never gets an answer never calls it.
.onShowingChange(_:) modifier in SwiftUI and the onShowingChange property of GiftsButtonView in UIKit. On Android it is the onShowingChange parameter of GiftsButton in Compose and the onShowingChange property of GiftsButtonView. You can set either property at any time.
Tile look
The tile is a look made for host state, sized for a half-width slot in a two-column grid. While locked it draws a ring around the gift that fills withprogress, and a line of text under it. When ready, or with no host state, it draws a full ring and opens the sheet on a tap. When done it draws a full ring with its done text.
- It fills the width you give it. Give it the width of its grid slot and leave the height to it.
- Its height follows its width. The tile sets its height from its own aspect ratio, so it is taller than it is wide. Its height is capped at 320 points on iOS and 320
dpon Android. On a wide screen it reaches the cap and its content stays centered. - Your
headlinereplaces the locked line. Leave it out and the tile shows its own copy. See Your text.
After a claim
Encore decides what the spot shows after the user claims an offer, and can test the choices against each other. Usually Gifts Button turns into a Claim Reminder: the same spot reminds the user to finish that claim, with a countdown, and a tap opens the reward sheet with that offer in it. It turns back into Gifts Button when any of these happens:- The claim is completed. Encore confirms the user finished it.
- The reminder window ends. That is 24 hours after the claim by default; Encore sets it with the look.
- The user taps ×. Every claim it was reminding about is hidden on this device. A claim made later brings the reminder back.
- The offer leaves the sheet. For example, the brand paused the campaign, or the campaign reached its cap.
show() call, as long as this placement’s sheet still lists that offer. The SDK keeps the user’s claims on the device, so the reminder also shows after the app reopens, until one of those four things ends it. The spot’s request for its look includes whether a claim is open, so Gifts Button doesn’t flash first. A claim counts as open while it’s inside the reminder window last served at this placement, which the device remembers across launches; until one is served there, that’s 24 hours.
The reminder in the spot keeps its own look and analytics. Don’t also mount a Claim Reminder at the same spot: the user could see the reminder twice.
The height changes. Reminder looks are 76 points tall (pixels on the web), and the featured look is 85. Gifts Button’s looks are 48 to 112. The entry takes its new height at once while the content fades across, so leave room in your layout for it to grow or shrink.
After a completion
A claim is completed when Encore confirms the user finished the offer. On iOS and Android, a user telling the sheet they finished it counts too. An expired or failed claim is not a completion. The entry asks Encore about the user’s newest open claims when the screen opens and when the app comes back to the foreground, so a completed claim stops showing as a reminder. After a completion, Encore decides what the spot shows for the rest of the user’s day, and can test the choices against each other:- Gifts Button while its sheet has offers, as before.
- Nothing, until midnight on the user’s device or until they claim another offer, whichever comes first.
- A thanks look: “Nice work, you finished it” with “More gifts are waiting” and a “See gifts” button, and no logos. A tap opens the reward sheet as Gifts Button does, and the spot goes back to Gifts Button. So do a new claim and midnight on the user’s device. Its events carry the layout
thanks.
What Encore controls
The served look sets the layout, the height, the copy (in the user’s language) for each line you don’t set yourself, the default colors, and what the spot shows after a claim and after a completion. Encore can test several looks against each other, so different users can see a different entry. Yourappearance colors always win, in the color order.
The entry never names the reward.
Analytics
Gifts Button reports its own impressions and taps to Encore’s analytics. You don’t send any events. While you set a host state, its events also carry the status, never the progress.Related
- Trigger components: how trigger components work, heights, and colors.
- Quickstart and Experiments and looks.
- Reward Users: the use case whose sheet Gifts Button opens.
- Localization: how the entry’s copy reaches the user’s language.