This function is useful when you want to:
- Process user answers before showing the paywall,
- Send answers to a backend or external API,
- Extract a value from the response (e.g., external_user_id),
- Save that value with AnalyticsManager.setUserProperty,
- Ensure redirection to the paywall happens only after processing is done.
function (answers, callback) {
// 1. Send the answers to your API
fetch('https://your-api.com/process-answers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// Optional: Add authorization header if needed
// 'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({ answers: answers })
})
.then(response => {
if (!response.ok) {
throw new Error('API error');
}
return response.json();
})
.then(data => {
// 2. Extract external_user_id
const externalUserId = data.external_user_id;
// 3. Save it as a user property
if (externalUserId) {
AnalyticsManager.setUserProperty('external_user_id', externalUserId);
}
// 4. Continue to the paywall
callback();
})
.catch(error => {
console.error('Failed to send answers or parse response:', error);
// Still proceed to paywall if API fails (fallback)
callback();
});
}
🧠 Notes
- Replace 'https://your-api.com/process-answers' with your actual API endpoint.
- You can enrich the payload (e.g., include user_id, session_id, or other metadata if needed).
- Make sure the endpoint responds quickly to avoid delays in redirection.
- Always call callback() to allow the flow to continue — even on failure.