Content Builder Block SDK

The Content Builder Block SDK allows developers to create custom content blocks for use within Email Studio, Content Builder, and CloudPages in Salesforce Marketing Cloud (SFMC). These blocks enable dynamic and interactive content, leveraging JavaScript, HTML, and APIs to extend SFMC’s default content capabilities.

🔹 Key Features of Content Builder Block SDK

                    ✅ Create custom interactive content blocks (e.g., countdown timers, product recommendations).
                    ✅ Use JavaScript, HTML, CSS, and SFMC APIs to enhance block functionality.
                    ✅ Integrate with third-party APIs (e.g., real-time pricing, weather updates).
                    ✅ Store and retrieve block settings using SFMC’s Supermessage API.
                    ✅ Support for cross-channel content in Emails, CloudPages, and SMS.

🔹 Prerequisites

  • Access to Salesforce Marketing Cloud (SFMC).
  • SFMC Admin permissions to enable custom blocks.
  • Basic knowledge of JavaScript, HTML, and SFMC APIs.
  • A local or cloud-based development environment (e.g., Node.js, VS Code).

🔹 Steps to Implement a Custom Block Using Content Builder SDK

1.Setup a New Custom Block

  1. Navigate to Content Builder in SFMC.
  2. Click “Create New” → “Content Block” → “Custom Block”.
  3. Provide a Block Name and description.
  4. Select Block Type (e.g., HTML, JavaScript).
 

2. Load the SDK in Your Custom Block

Include the Content Builder SDK in your custom block to interact with SFMC.

<script src=”https://blocksdk.com/blocksdk.js”></script>

<script>

  var sdk = new window.sfdc.BlockSDK();

</script>

3.Retrieve and Store Block Settings

Use the SDK to store and retrieve custom block settings.

var sdk = new window.sfdc.BlockSDK();

sdk.getData(function(data) {

    var savedText = data.text || “Enter your content here”;

    document.getElementById(“customText”).value = savedText;

});

document.getElementById(“customText”).addEventListener(“input”, function() {

    sdk.setData({ text: this.value });

});

4.Create a Simple Custom Block UI

Add an input field for text content that users can modify.

<input type=”text” id=”customText” placeholder=”Enter custom text” />

5.Save & Deploy the Custom Block

  1. Click “Save” and test the block inside Content Builder.
  2. Drag and drop it into an email template or CloudPage.
  3. Verify dynamic content updates before sending.

🔹 Example: Creating a Countdown Timer Block

Here’s an example of a custom countdown timer block for an email.

1.JavaScript Logic

var sdk = new window.sfdc.BlockSDK();

function startCountdown() {

    var deadline = new Date(“2025-12-31T23:59:59”).getTime();

    var x = setInterval(function () {

        var now = new Date().getTime();

        var timeLeft = deadline – now;

        var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));

        var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

        var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));

        var seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);

        document.getElementById(“countdown”).innerHTML =

            days + “d ” + hours + “h ” + minutes + “m ” + seconds + “s “;

    }, 1000);

}

window.onload = startCountdown;

2.HTML UI for Countdown Timer

<div>

    <h3>Countdown Timer</h3>

    <p id=”countdown”></p>

</div>

🔹 Best Practices for Content Builder Block SDK

✅ Use BlockSDK Methods (getData(), setData()) to manage settings.
✅ Optimize Performance (avoid heavy API calls in the block).
✅ Ensure Mobile Responsiveness (use CSS & media queries).
✅ Test in Multiple Environments (Email Studio, CloudPages).
✅ Use External APIs for real-time data (e.g., weather, stock prices).

🔹 Additional Use Cases for Custom Blocks

  •  Dynamic Product Recommendations (fetch live data from eCommerce API).
  • Real-time Weather Updates (use OpenWeather API).
  • User Preference Forms (collect data & update Data Extensions).
  • Personalized Offers (use AMPscript & JavaScript).