Guide
Welcome to the Quick Start Guide for the IDR Subscription SDK. This guide will help you set up and use the SDK in your projects quickly and effectively.
This guide contains the required steps to include the SDK on your website and quickly start rendering content.
<html>
<head>
<!-- Include the IDR SDK file -->
<script src="idr-sdk.js"></script>
<!-- Initialise the SDK -->
<script>
IdrSDK.init({
apiKey: 'YOUR_API_KEY',
// Define the container where the subscription content will be rendered
container: '.subscription-container',
});
// Choose a URL to render and an optional CSS file for custom styling
IdrSDK.renderUrl('YOUR_RENDER_URL');
// Choose a callback action
IdrSDK.on('subscriptionComplete', (data) => {
console.log('Subscription Complete:', data);
});
</script>
</head>
<body>
<div class="subscription-container">
<!-- The subscription content will be rendered here -->
</div>
</body>
</html>
To use the IDR SDK in your project, include the idr-sdk.js file in your HTML page:
<html>
<head>
<script src="idr-sdk.js"></script>
</head>
</html>
Make sure to replace path/to/idr-sdk.js with the actual path to the SDK file on your server.
Before using any functionality, you must initialise the SDK. Call the init() method with an options object that includes your API key and the container to render content into:
<script>
IdrSDK.init({
apiKey: 'YOUR_API_KEY',
// Define the container where the subscription content will be rendered
container: '.subscription-container',
});
</script>
The init() method will check if the SDK is already initialised, and ensure that the container and API key are valid.
Once the SDK is initialised, you can render content into the default container or a specified container:
<script>
// ...
IdrSDK.renderUrl('YOUR_RENDER_URL');
// ...
</script>
If you don't specify a container, the content will be rendered into the default container provided during initialisation.
Choose a callback action upon successful subscription, if needed:
<script>
// Define a callback function (optional)
IdrSDK.on('subscriptionComplete', (data) => {
console.log('Subscription Complete:', data);
});
// ...
</script>
The IDR SDK supports custom styling to match your brand identity. We work with you to create a tailored stylesheet that seamlessly integrates with your website's design.
<script>
IdrSDK.init({
apiKey: 'YOUR_API_KEY',
container: '.subscription-container',
// Reference your newly created stylesheet
stylesheet: 'https://cdn.idr-sdk-demo.com/styles/your-company.css',
});
</script>
| Parameter | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Yes | Your API key for authenticating with the SDK services. |
| container | string | Yes | CSS selector for the container element where content will be rendered. |
| url | string | Yes | The URL of the content to be rendered inside the iframe. |
| eventName | string | Yes | Name of the event to listen for or trigger. |
| callback | function | Yes | Function to be executed when the specified event is triggered. |
| data | object | No | Optional data object to pass to event listeners. |
init(options)Initialises the SDK with the provided configuration.
Example:
IdrSDK.init({
apiKey: 'your-api-key',
container: '#my-container'
});
renderUrl(url, [containerSelector])Renders content inside a container, either the default container or a specified one. The content is displayed in an iframe.
Example:
IdrSDK.renderUrl('https://example.com', '#my-container');
on(eventName, callback)Registers an event listener for a custom SDK event.
Example:
IdrSDK.on('contentLoaded', function(data) {
console.log('Content loaded successfully:', data);
});
trigger(eventName, data)Triggers a custom event that will invoke any listeners registered with on().
Example:
IdrSDK.trigger('contentLoaded', { success: true });