Implementing Clickthrough in your application is a straightforward process with the SpotDraft Clickthrough SDK. This guide will walk you through the steps to seamlessly integrate Clickthrough and enhance the user experience on your website.
Add the Clickthrough SDK to Your Application
- Begin by importing the Spotdraft Clickthrough SDK into your application.
- Add the following script tag to your HTML file (preferably in the head section)
<script type="module"
src="<https://sdk.spotdraft.com/clickwrap/v1/sdk.js>"></script>
This script tag establishes the connection between your application and the Clickthrough SDK.
Set Up the Clickthrough Object
- Once the Clickthrough object is attached to the window, create a new Clickthrough object through constructor initialization.
window.addEventListener("sdClickthroughLoaded", function () {
const clickthrough = new SdClickthrough({
clickwrapId: "CLICKWRAP_ID_FROM_CONSOLE",
hostLocationDomId: "HOST_ELEMENT_DOM_ID",
baseUrl: "BASE_URL_FROM_CONSOLE"
});
})
- You can obtain the values for clickwrapId and baseUrl from the Clickthrough snippet from the SpotDraft console.
- The hostLocationDomId is the ID of the placeholder element in your application, where the Clickthrough will be rendered. For example:
<div id="some-unique-id"></div>
- To attach the Clickthrough elements to the UI, use:
clickthrough.init();
Your website will now display the Clickthrough element within the specified placeholder container.
Execute Your First Clickthrough Contract
- With the Clickthrough element in place, you can execute the Clickthrough contract when a user takes an action, such as submitting a form or clicking a button.
- To do this, use the submit() method on the Clickthrough object with the appropriate payload data:
clickthrough.submit(payload).then(contractData => {
// Continue with your actions
})
- The payload you send with the submit method should have a structure like this:
const payload = {
user_identifier: 'johndoe@example.com', // This is a required field
first_name: 'John',
last_name: 'Doe',
user_email: 'johndoe@example.com',
};
‘user_identifier’ is the only required field. Other properties, if included, will be added to the audit log when the contract is executed. The user_identifier has to be a string that uniquely identifies the user on your platform, like an email address or mobile number.
By following these simple steps, you can seamlessly integrate Clickthrough into your application and provide a user-friendly way for users to accept agreements with a single click. Additionally, you can easily track executed Clickthrough contracts in the SpotDraft Clickthrough console.
Access the SpotDraft Clickthrough API documentation here for further information.