@clickmax/checkout-react 12.5.16 → 12.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -106,7 +106,23 @@ Every component takes `className` and a `children` render function. With the fun
106
106
  </PersonalDataFields>
107
107
  ```
108
108
 
109
- The same state is available through hooks: `useOfferItem`, `useOrderBumps`, `usePersonalData`, `useAddress`, `useFreight`, `usePayment`, `useCoupon`, `useSummary`, `useSubmit`, `usePix`, `useBoleto`, `useCountdown`, `useUpsell`, and `useCheckout` for everything.
109
+ The same state is available through hooks: `useOfferItem`, `useRecurrence`, `useOrderBumps`, `usePersonalData`, `useAddress`, `useFreight`, `usePayment`, `useCoupon`, `useSummary`, `useSubmit`, `usePix`, `useBoleto`, `useCountdown`, `useSocialProof`, `useUpsell`, and `useCheckout` for everything.
110
+
111
+ ## Social proof
112
+
113
+ When the seller turns social proof on for the offer, `SocialProof` shows one balloon at a time: recent purchases and charges first ("***na S. bought", with city and time), then the counts the seller enabled ("12 people purchased in the last 24 hours", views, order bumps), up to the seller's maximum of balloons. The window and the minimum of each count come from the offer settings and are applied by the API, so a count below its minimum never reaches the page.
114
+
115
+ ```tsx
116
+ <SocialProof className="fixed bottom-6 left-6 z-20 max-w-sm" />
117
+ ```
118
+
119
+ The first balloon shows 8 seconds after the page loads, each one stays 5 seconds (longer while the pointer or focus is on it) and the next comes 10 seconds later. The close button hides them for the rest of the visit, and none shows after the buyer sends the payment. Counts load once per visit and recent activity every 15 seconds, only while `SocialProof` is mounted: render it once per page. The default markup is a live region (`data-cx-checkout="social-proof"`) that you position; with a render function, `useSocialProof()` gives `balloon` (`parts` with the bold pieces, `icon`, `place`, `time`), `leaving`, `setEngaged` and `dismiss`.
120
+
121
+ ## Notices, coupons and audiences
122
+
123
+ `CheckoutNotices` shows what the buyer must know about the offer: not for sale (with the seller's support email), waiting for approval, email outside the offer's audience, free trial already used, and the free Clickmax account an affiliate-split purchase creates. `useCheckout().availability.status` tells whether to hide the form; the submit buttons stay disabled and `submit` fails without calling the API while the offer is not for sale or the email is outside its audience.
124
+
125
+ Once the buyer's email settles (600 ms after typing stops), the checkout asks the server for the best automatic coupon of that email and applies it when it beats the coupon already applied; `coupon.source` is `'auto'` and `CouponField` shows it even when the offer hides the coupon field. The same email is checked against restricted audiences: bumps outside it are disabled and leave the order (`ineligible: true`).
110
126
 
111
127
  ## Callbacks
112
128
 
@@ -118,13 +134,60 @@ The same state is available through hooks: `useOfferItem`, `useOrderBumps`, `use
118
134
  |`onBoletoGenerated`|A boleto was issued.|
119
135
  |`onUpsellAccepted`|The one-time offer was bought.|
120
136
  |`onUpsellDeclined`|The buyer declined the one-time offer (`downsellUrl`).|
137
+ |`onPixelEvent`|An offer pixel should fire in the browser (see below).|
121
138
 
122
139
  Callbacks never block the flow. Redirects are up to you.
123
140
 
141
+ ## Leads and pixels
142
+
143
+ The checkout records the buyer as a lead once the email is valid and a personal data field loses focus, and records the payment step when the buyer picks a method or focuses the card. Both start cart abandonment. The field props of `PersonalDataFields` already call `captureLead`; with fully custom inputs, call `usePersonalData().captureLead()` on blur. Pass `location.visitorId` and `location.sessionId` from your analytics so abandonment links to the visit.
144
+
145
+ Offer pixels (Meta, Google Ads) go two ways with the same event id, so the platform counts each event once:
146
+
147
+ - In the browser, by you: the package does not load `fbq` or `gtag`. `onPixelEvent` gives the event (`pageView`, `initiateCheckout`, `addPaymentInfo`, `purchase`), the pixels set to track it, and the `eventId` each one must send.
148
+ - To the conversions API, by the package: `initiateCheckout` and `addPaymentInfo`, with the buyer data typed so far. Purchases reach it from the server.
149
+
150
+ ```tsx
151
+ const META_EVENTS = {
152
+ pageView: 'PageView',
153
+ initiateCheckout: 'InitiateCheckout',
154
+ addPaymentInfo: 'AddPaymentInfo',
155
+ purchase: 'Purchase',
156
+ }
157
+
158
+ <CheckoutProvider
159
+ offer={offer}
160
+ location={{ visitorId, sessionId }}
161
+ onPixelEvent={({ name, pixels, amountCents, currency }) => {
162
+ for (const { pixel, eventId } of pixels) {
163
+ if (pixel.service === 'facebook') {
164
+ window.fbq?.('trackSingle', pixel.serviceId, META_EVENTS[name], {
165
+ ...(amountCents !== undefined ? { value: amountCents / 100, currency } : {}),
166
+ }, { eventID: eventId })
167
+ }
168
+ }
169
+ }}
170
+ >
171
+ ```
172
+
173
+ Events wait for the visitor route, whose session id builds the ids. `initiateCheckout` fires on load, or once name, email and phone are filled when the pixel asks for it (`afterPersonalData`). `addPaymentInfo` fires once, when the buyer picks a method, focuses the card, or the checkout opens on pix or boleto.
174
+
124
175
  ## One-time offers (upsell and downsell)
125
176
 
126
177
  For an offer with `isOTO`, render `UpsellAcceptButton` and `UpsellDeclineButton`. A page with no Clickmax page configuration declares the kind of page with `getPublicOffer({ offer, mode: 'upsell' })` (or `'downsell'`), which sets `isOTO`. The declaration only changes the interface: buying without card data still needs the previous purchase in the same browser. A returning buyer with a saved card buys with one click; otherwise render the buyer form and `CardFields` as in a regular checkout.
127
178
 
179
+ ## Subscriptions and installments
180
+
181
+ For a recurring offer, `Price` adds the period suffix ("/mês", "/ano") and `Recurrence` (rendered by `OfferItem`) shows the free trial with what is charged after it, following the installment the buyer picked, and the charge limit when the subscription ends on its own. During a free trial the price today is zero. `useRecurrence()` gives the terms (`frequency`, `interval`, `gracePeriod`, `tolerancePeriod`, `maxCharges`) and the ready texts; it is `undefined` for one-time offers.
182
+
183
+ When the seller highlights the installment (`offer.highlightInstallment`), `Price` leads with "12x R$ 49,70" and the cash price follows (`data-highlight="true"`). Order bumps with a free trial show "R$ 0,00 por 30 dias" and the later charge (`bump.trial`), with the seller's own texts when set.
184
+
185
+ ## Address and pix after a reload
186
+
187
+ For Brazilian buyers, a complete zip code fills street, neighborhood, city and state through ViaCEP. Pass `zipCodeLookup` to use your own lookup, or `false` to turn it off; `useAddress().lookup.status` tells when it runs.
188
+
189
+ A generated pix is kept in the tab's `sessionStorage` (code, QR code, amount and expiry only, nothing about the buyer). When the buyer reloads the page, the provider shows it again after hydration and keeps checking it, so `onApproved` still fires once it is paid; `onPixGenerated` does not fire again (`usePix().restored`). Turn it off with `restorePendingPix={false}`, for example in previews.
190
+
128
191
  ## Prices
129
192
 
130
193
  All amounts are integers in cents. `useSummary().formatted` and `formatMoney(cents, locale)` format them. Until the server pricing answers, the summary shows the offer's own prices and `isEstimate` is `true`.