My Development Environment for SFMC CloudPages using ‘ContentBlockByKey’ and VSCode.

The story is aimed at enhancing the user experience during code development in SFMC CloudPages using community resources.

My Development Environment for SFMC CloudPages using ‘ContentBlockByKey’ and VSCode.
Photo by Fernando Hernandez on Unsplash

More recently, I have started code development in SFMC CloudPages and I desperately needed an efficient process to develop, publish and test the script.

By all means, there are a few other ways that will serve you the same outcome, however, I think using GitHub, Dropbox, GDrive, etc has some dependencies and risks:

  • install the software (DropboxGDrive) to sync the local files to the cloud on your PC
  • using GitHub required code commits and storing the personal access tokens on CloudPages.
  • risk of running into malware detections from cloud storage service providers due to SFMC programmatic scripts (personally, this is the worst as those cloud storage service providers like Google can block your SFMC CloudPage sub-domain)

Alright, let’s dive into this development setup that I have recently used — for this purpose you’d need a few things configured:

  • Microsoft VSCode (code editor that everyone uses these days — needs no introduction)
  • a VSCode extension MCFS [AMPScript] (this Virtual filesystem for Marketing Cloud enables access to your SFMC org — also comes with other great features like AMPScript syntax highlighting, inbuilt documentation, and code snippets)
  • An installed Package in your SFMC Org (refer below for configuration steps)

1. Create and Install Packages

Go ahead and install Microsoft VSCode with a VSCode extension MCFS [AMPScript] if you haven’t done so, then you’ll need an Installed Package setup in SFMC — specifications follow:

i) In Marketing Cloud, go to Setup Apps Installed Packages | Click New.

ii) Give the package a name and description | Save the package.

iii) Under Components, click Add Component | select a component as “API Integration” and add the following permissions:

  • ASSETS: Saved Content (Read and Write) — this permission will be required by the MCFS [AMPScript] extension to update the content block in SFMC.

2. Setup a Content Block

This section will assist you in setting up a content block where your development code will be hosted.

i) Navigate to Content Builder | Create | Content Blocks | HTML

ii) Leave the content block body empty and save it with a readable “Customer Key” (this will be useful during the CloudPages setup)

Note: Currently, the Code Snippet block supports view-only access — leaving HTML as the next best option for code development.

3. Configure your landing page (CloudPages)

In this section, we will configure the landing page/code resource so it can reference the content block we’ve created in Step 2 (Setup a Content Block).

i) Navigate to your CloudPage collection and create a new landing page or any code resource.

ii) In this step, you’ll need to reference your content block using the ContentBlockByKey function.

a) AMPScript version:

b) SSJS version:

Note: The content block will also need the core library and the script declarations.

4. Configure your VSCode and MCFS [AMPScript] extension

Now we will use the MCFS [AMPScript] extension to connect with the SFMC org virtually and access the content block created in the Content Builder.

Follow the guide on the extension homepage to virtually connect with the SFMC org.

Reference: Agadzhanov Sergey

Once connected, under Content Builder, you’ll find your content block — open the “.amp version of the file.

SFMC content block with .amp extension

That’s it. Go ahead and develop code/script straight in your VSCode editor — see results on your landing page instantly!🥳

A few quirks to note

  • Code formatter like Beautify might not function on the content blocks — potentially due to virtual limitations.
  • Connection to SFMC org might randomly disconnect if left idle for too long — in this event just restart your VSCode app.
  • A quick tip: save your content block in your folder — it’s much easier to search a folder than a file amongst hundreds.
  • Your ClientID and ClientSecret credentials will be stored in your VSCode user settings JSON file — be aware of the security risks and you can always delete the package in SFMC for reassurance.
  • Be aware of the Content Block’s anomalous support with client-side JS. (credit: Gregory Gifford)
  • Lastly, please ensure your script/code has been migrated from Content Blocks to CloudPages for production.