JavaScript integration
This page explains how to integrate Capping with the JavaScript SDK.
Install the SDK
Add the SDK script into your html, just before the closing body tag:
<script async src="https://capping.sirius.press/sdk.v1.1.0.js"></script>
Initialize the SDK
Declare the configuration in a script placed before the SDK script.
Make sure to set the user ID or the tracking will not work.
<script>
var siriusCapping = window.siriusCapping || {};
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
};
</script>
<script async src="https://capping.sirius.press/sdk.v1.1.0.js"></script>
| Parameter | Type | Description |
|---|---|---|
siriusCapping.config.brand | string | The ID of your brand, that we will give you. |
siriusCapping.config.userId | string | The ID of the user, that you can write encrypted or hashed. |
The SDK reads window.siriusCapping.config once, when the script loads, and its functions are available from that moment. To change the user, reload the page.
Start and stop tracking
Tracking starts automatically when the SDK loads, without any blocking. The SDK follows the tab visibility: it stops tracking when the tab is hidden, and resumes when the tab becomes visible again.
To stop tracking, call:
siriusCapping.stop();
Tracking resumes when the tab becomes visible again. The device remains counted as connected for up to 10 seconds.
Display a blocking message
You are responsible for building the UI that blocks content. Add it to your html, then give the SDK the function that shows it.
<div id="capping" style="display: none">
<p>Your subscription is used on another device.</p>
</div>
<script>
var siriusCapping = window.siriusCapping || {};
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
showPopinFunction: function (response) {
var popin = document.getElementById("capping");
// Adapt the message to the rule that blocked the device
if (response.blockReasons[0] === "<ACTION_NAME_1>") {
popin.style.color = "red";
} else if (response.blockReasons[0] === "<ACTION_NAME_2>") {
popin.style.color = "orange";
}
popin.style.display = "block";
},
};
</script>
<script async src="https://capping.sirius.press/sdk.v1.1.0.js"></script>
| Parameter | Type | Description |
|---|---|---|
siriusCapping.config.showPopinFunction | function | Called with the server response when the device is blocked. The SDK then sends the popinDisplayed event. |
The response object has the following properties:
| Property | Type | Description |
|---|---|---|
blockReasons | string[] | Names defined in the Action field of the rules that blocked the device, without duplicates. Can be empty. |
Track events
Displaying a blocking message will help generate conversions or upsell. To reconcile conversions with popin displays, you can ask the SDK to collect a conversion event. For example, here’s how to do it on your purchase confirmation page.
<script>
var siriusCapping = window.siriusCapping || {};
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
mode: "conversion",
};
</script>
<script async src="https://capping.sirius.press/sdk.v1.1.0.js"></script>
Observe copy-paste
In addition to account sharing, you may want to monitor how users copy your content. Activate “Copy Paste Observer” to track copy actions and modify the copied content. It is only available with the JavaScript SDK.
Track copies
Add a dedicated configuration to your Capping integration:
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
copyPasteObserver: {
enable: true,
characterLimit: 140, // Track copies longer than this number of characters
},
};
| Parameter | Type | Description |
|---|---|---|
siriusCapping.config.copyPasteObserver.enable | bool | Set it to true if you want to track copies. |
siriusCapping.config.copyPasteObserver.characterLimit | int | Copies longer than this number of characters are tracked. |
Modify the copied content
Use the modifications array to change the copied content.
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
copyPasteObserver: {
enable: true,
characterLimit: 140, // Track copies longer than this number of characters
modifications: [
{
type: "prepend|append|replace",
text: "<br>This is a message that will be added before/after the copied content or will replace it (depending on the modification type)<br><br>",
},
],
},
};
| Parameter | Type | Description |
|---|---|---|
siriusCapping.config.copyPasteObserver.modifications | object | An array of objects that defines the changes to be made to the copied content, if any. Each object contains the following keys. |
siriusCapping.config.copyPasteObserver.modifications[].type | string | A string that indicates the type of modification to be made. The possible values are prepend (to add text at the beginning), append (to add text at the end) and replace (to replace the copied content). |
siriusCapping.config.copyPasteObserver.modifications[].text | string | A string that contains the text to add or replace in the copied content. HTML is allowed: tags are removed from the plain-text version. |
Change the modification after several copies
The modifications array allows you to change the type of replacement depending on the number of copy occurrences. Only one modification applies to a copy: the last entry matching the count. An entry without count applies by default.
siriusCapping.config = {
brand: "<BRAND_ID>", //mandatory
userId: "<USER_ID>", //mandatory
copyPasteObserver: {
enable: true,
characterLimit: 140, // Track copies longer than this number of characters
modifications: [
{
type: "prepend",
text: "<br>This is a message that will be added before the copied content<br><br>",
},
{
type: "replace",
text: "This message will replace the copied content after 5 copies.",
count: {
min: 5,
max: 10,
},
},
{
type: "replace",
text: "This message will replace the copied content after 10 copies, and will stop counting.",
count: {
min: 11,
stopCounting: true,
},
},
],
},
};
| Parameter | Type | Description |
|---|---|---|
siriusCapping.config.copyPasteObserver.modifications[].count | object | An optional object that defines limits on the number of times the change should be applied. It contains the following keys. |
siriusCapping.config.copyPasteObserver.modifications[].count.min | int | An integer that defines the minimum number of copies to apply the change. |
siriusCapping.config.copyPasteObserver.modifications[].count.max | int | An integer that defines the maximum number of copies to apply the change. |
siriusCapping.config.copyPasteObserver.modifications[].count.stopCounting | bool | A boolean that defines if the counter should stop counting once min is reached. |
siriusCapping.config.copyPasteObserver.countTimeWindow | string | Period over which copies are counted: a number followed by s, m, h or d. Default: 7d. |
Deactivate Capping
If you don’t want to launch Capping, do not define siriusCapping.config.brand and siriusCapping.config.userId, and/or do not insert the JavaScript SDK.