({
targetId,
campaignId,
requestDelayMs = appStoreReviewRequestDelayMs,
onRequestClose,
}: {
targetId: string;
campaignId?: string;
requestDelayMs?: number;
onRequestClose?: (event: CloseEvent) => void;
})
| 21 | * Customer.io marketing CTA behind it on any close so it is asked once. |
| 22 | */ |
| 23 | export const useAppStoreReviewAsk = ({ |
| 24 | targetId, |
| 25 | campaignId, |
| 26 | requestDelayMs = appStoreReviewRequestDelayMs, |
| 27 | onRequestClose, |
| 28 | }: { |
| 29 | targetId: string; |
| 30 | campaignId?: string; |
| 31 | requestDelayMs?: number; |
| 32 | onRequestClose?: (event: CloseEvent) => void; |
| 33 | }): UseAppStoreReviewAsk => { |
| 34 | const { clearMarketingCta } = useBoot(); |
| 35 | const { logEvent } = useLogContext(); |
| 36 | const hasOpened = useRef(false); |
| 37 | const hasRated = useRef(false); |
| 38 | |
| 39 | useEffect(() => { |
| 40 | if (hasOpened.current) { |
| 41 | return; |
| 42 | } |
| 43 | hasOpened.current = true; |
| 44 | |
| 45 | logEvent({ |
| 46 | event_name: LogEvent.Impression, |
| 47 | target_type: TargetType.AppStoreReview, |
| 48 | target_id: targetId, |
| 49 | }); |
| 50 | |
| 51 | // Scheduled when the surface opens and never cancelled: closing it early |
| 52 | // must not turn the pop-up into something only people who stay get, which |
| 53 | // would be the review gating Apple rejects. The one skip is a reader who |
| 54 | // already tapped Rate: they are on the App Store writing a review, so the |
| 55 | // pop-up would only spend one of Apple's yearly prompts on them. |
| 56 | setTimeout(() => { |
| 57 | if (!hasRated.current && requestIOSReview()) { |
| 58 | logEvent({ |
| 59 | event_name: LogEvent.RequestAppStoreReview, |
| 60 | target_type: TargetType.AppStoreReview, |
| 61 | target_id: targetId, |
| 62 | }); |
| 63 | } |
| 64 | }, requestDelayMs); |
| 65 | }, [logEvent, requestDelayMs, targetId]); |
| 66 | |
| 67 | const close = (event: CloseEvent, eventName: LogEvent) => { |
| 68 | logEvent({ |
| 69 | event_name: eventName, |
| 70 | target_type: TargetType.AppStoreReview, |
| 71 | target_id: targetId, |
| 72 | }); |
| 73 | if (campaignId) { |
| 74 | clearMarketingCta(campaignId); |
| 75 | } |
| 76 | onRequestClose?.(event); |
| 77 | }; |
| 78 | |
| 79 | return { |
| 80 | onRate: (event) => { |
no test coverage detected