Question
How to deploy Javascript SDK code in a Wordpress site?
Answer
The steps below explain how to use Javascript SDK in a blank page within a Wordpress site
1- First step is to install Header and Footer Scripts plugin. While this is not required, it is a good practice to load the Javascript SDK library within the page header.
2- In your Site Development page, create a sample page.
3- Open the page in Edit mode, scroll to the bottom and paste the import script tag under Insert Script to <Head> section
<script src="https://cdn.split.io/sdk/split-10.21.1.min.js"></script>
4- Click on the + sign to insert new block, and choose Custom HTML
5- The Custom HTML block allows any HTML elements, including Javascript, copy and paste the code below inside it, make sure to replace the API KEY with a valid key, set the User key and feature flag name as well.
<p id="sdk"></p>
<script>
factory = splitio({ core: {
authorizationKey: 'SDK API KEY',
key: 'USER KEY',
},
startup: {
readyTimeout: 4, requestTimeoutBeforeReady: 4
},
});
client = this.factory.client();
client.on(client.Event.SDK_READY, () => {
treatment = client.getTreatment("SPLIT NAME");
console.log("treatment = "+treatment);
var pobj = document.getElementById("sdk");
pobj.innerHTML = "<p>Split: [SPLIT NAME], Treatment = "+treatment+"</p>";
});
</script>
6- Save and review the page, once it loads, the treatment is calculated after the SDK_READY event fires and display the feature flag name and treatment value, in the <p> section.
Comments
0 comments
Please sign in to leave a comment.