diff --git a/scenarios/ReactExamples/SingupExample/app.js b/scenarios/ReactExamples/SingupExample/app.js new file mode 100644 index 0000000..5b72ac0 --- /dev/null +++ b/scenarios/ReactExamples/SingupExample/app.js @@ -0,0 +1,23 @@ +import React from "react"; +import {loadHaptikSdk} from "./loadHaptikSDK" + +class LoadSDK extends React.Component { + constructor(props) { + super(props); + this.state = { + "bot_details": { + "business-id": YOUR_BUSINESS_ID, + "client-id": "YOUR_CLIENT_ID", + "base-url": "BASE_URL" + } + }; + } + componentDidMount() { + loadHaptikSdk(this.state.bot_details); + } + render() { + return (

This is your website...

); + } +} + +export default LoadSDK; \ No newline at end of file diff --git a/scenarios/ReactExamples/SingupExample/loadHaptikSDK.js b/scenarios/ReactExamples/SingupExample/loadHaptikSDK.js new file mode 100644 index 0000000..628b283 --- /dev/null +++ b/scenarios/ReactExamples/SingupExample/loadHaptikSDK.js @@ -0,0 +1,27 @@ +const loadHaptikSdk = (botDetails) => { + const existingScript = document.getElementById('my_haptik_script'); + if(!existingScript){ + window.haptikInitSettings = botDetails; + const script = document.createElement('script'); + script.src = "https://toolassets.haptikapi.com/platform/javascript-xdk/production/loader.js"; + document.body.appendChild(script); + + document.addEventListener('haptik_sdk', function () { + // signup example can be removed if signup is not used + window.HaptikSDK.signup( + { + "auth_id": "YOUR_AUTH_ID", + "auth_code": "YOUR_AUTH_CODE", + 'signup-type': 'third_party' + },function(status){ + if(status){ + console.log("Singup API call success"); + }else{ + console.log("Singup API call failed"); + } + } + ); + }); + } +} +module.exports.loadHaptikSdk = loadHaptikSdk; \ No newline at end of file