Handle Message Function:
const handleMessage = (event) => {
const { data } = event.nativeEvent;
try {
const parsedData = JSON.parse(data);
if (parsedData.event === "calendly.event_scheduled") {
console.log("Event scheduled successfully");
} else {
console.log("Received Calendly event data:", parsedData);
}
} catch (error) {
console.error("Error parsing message from WebView:", error);
}
};
const calendlyUrl = "https://calendly.com/yourUrl";
Injected Javascript:
const injectedJavaScript = `
(function() {
var script = document.createElement('script');
script.src = 'https://assets.calendly.com/assets/external/widget.js';
script.async = true;
script.onload = function() {
Calendly.initInlineWidget({
url: '${calendlyUrl}',
parentElement: document.getElementById('calendly-container'),
prefill: {},
utm: {}
});
window.addEventListener('message', function(event) {
if (event.data.event) {
window.ReactNativeWebView.postMessage(JSON.stringify(event.data));
}
});
};
document.head.appendChild(script);
})();
true;
`;
Web View component
<WebView
originWhitelist={t"*"]}
source={{ uri: calendlyUrl }}
injectedJavaScript={injectedJavaScript}
onMessage={handleMessage}
javaScriptEnabled={true}
/>
Hi Team,
I'm currently working on capturing events triggered by Calendly in a React Native app. However, I'm facing an issue where the events are not consistently being captured. Could you please help me identify the possible causes and suggest solutions to fix this?
Thank you!