CONTENT BLOCKS

 CONTENT BLOCKS

AM THE BIGGEST FAN OF CONTENT BLOCKS. CONTENT BLOCKS ARE MAGICAL COMPONENTS FOR DESIGNING YOUR SFMC USE CASES. WITH THE USAGE OF CONTENT BLOCKS , YOU CAN CREATE A MODULAR DESIGN WHICH IS RESUABLE AND EASY TO FIX.

ADVANTAGES :

  1. REUSABLE 
  2. CAN BE USED ACROSS DIFFERENT ENVIRONMENTS
  3. REAL TIME CHANGES WITHOUT AFFECTING THE FLOW
  4. MODULAR DESIGN
  5. MORE EFFICIENT AND SCALABLE
  6. BUILT TIME IS SIMILAR TO STANDARD METHODS
DISADVANTAGE :
  1.   REQUIRE MORE AMPSCRIPT AND SSJS KNOWLEDGE


USE CASE :

WE NEED TO GENERATE A DEEPLINK TOKEN FOR OUR USER THAT WOULD HELP ENBALE THE USER FOR AUTO-LOGIN. THIS DEEPLINK TOKEN WILL BE GENRATED FROM AKAMAI API.
ONCE THIS TOKEN IS GENERATED, WE WILL APPEND THIS TOKEN TO THE URL IN THE EMAIL LINK.
FOR MORE DETAILS FOR AUTHORIZATION TOKEN, CLICK ON THE LINK 

DESIGN : 

WE WILL BUILT 3 CONTENT BLOCKS :- 
 1ST BLOCK WILL BE USED IN EMAILS ASKING THE MARKETERES TO SUPPLY SOME VALUE.
 2ND BLOCK WILL ASSIGN THE QUERY PARAMTERS 
 3RD BLOCK WILL CALL THE API USING SSJS

 
CREATE A CODE SNIPPET USING CONTENT BLOCK AND WRITE THE BELOW CODE 
   This content block will be pulled into the email using INSERT CODE SNIPPET menu from the email. This code will call the 2nd content block for assigning the query params. 
You can also use RaiseError function to validate if the marketers has supplied the initial value in the code snippet.
<!-----DEEPLINK FOR OFFER 1----->  
%%[
set @LinkName='Offer'
/* The Marketers has to provide the details*/
set @ClientId=''
set @RedirectUri=''
]%%
<!-----update link encoding ----->
%%=ContentBlockbyId("1234")=%%
<a alias="authToken" href="%%=RedirectTo(@offer)=%%">%%=v(@LinkName)=%%</a>
<!----- END OF DEEPLINK OFFER 1 ----->


CREATE A HTML CONTENT BLOCK TO ASSIGN THE QUERY PARAMTERS 
   This content block will simply assign the query parameters and call the content block that calls the API
/* ASSIGN QUERY PARAMETERS AND CALL AKAMAI API */
%%[
set @TypeName=''
set @KeyAttribute=''
set @LifeTime=''
set @KeyValue=''
set @EndPoint=''
set @HeaderValues=''
set @subscriberkey=_subscriberkey
]%%
YOU CAN HARD CODE THE QUERY PARAMETERS OR YOU CAN DO A LOOKUP TO A DATA EXTENSIONS.

/* GENERATE THE API TOKEN */
%%=ContentBlockbyId("5678")=%%

/* APPEND THE TOKEN TO THE USRL */
%%[
set @offer= Concat(@RedirectUri,'?authO=');
set @offer=Concat(@offer,@authorizationCode);
]%%


CREATE A HTML CONTENT BLOCK TO CALL THE API
  This code snippet will first pickup the AMPSCRIPT variables that was assigned in the 2nd block and with the query params we will built a payload that we need to attach to the API method. 
    We have also added encoding function for the query parameters to handle any special characters.
<script type="text/javascript" runat="server">
  Platform.Load("core", "1.1.1");
  try{
    function toFormEncoded(obj) {
      var newArr = [];
      if(typeof(obj)=='object') {
        for (var i in obj) {
          var encodedKey   = encodeURIComponent(i);
          var encodedValue = encodeURIComponent(obj[i]);
          newArr.push(encodedKey + "=" + encodedValue);
        }
        return newArr.join("&");
      }
    }

    //set JS varaible from ampscript variable
    var type_name = Variable.GetValue("@TypeName");
    var key_attribute = Variable.GetValue("@KeyAttribute");
    var lifetime = Variable.GetValue("@LifeTime");
    var for_client_id = Variable.GetValue("@ClientId");
    var key_value = Variable.GetValue("@KeyValue");
    var redirect_uri = Variable.GetValue("@RedirectUri");
    var headerValues = Variable.GetValue("@HeaderValues");
    var endPoint=Variable.GetValue("@EndPoint");
    var headerNames = ["Authorization"];
    var headerValues = [headerValues];
    var ContentType = "application/x-www-form-urlencoded";
    var setupURL =endPoint+"/access/getAuthorizationCode?";
    var payload = {
      'type_name': type_name,
      'key_attribute': key_attribute,
      'lifetime': lifetime,
      'for_client_id':for_client_id,
      'key_value':key_value,
      'redirect_uri':redirect_uri
    };
    setupURL = setupURL+toFormEncoded(payload);
    var authResponse = HTTP.Post(setupURL,ContentType,Stringify(payload),
headerNames,headerValues);
    var statusCode = authResponse["StatusCode"];
    Variable.SetValue("@statusCode",statusCode);
    Variable.SetValue("@authResponse",Stringify(authResponse));
    if(statusCode == 200)
    {
      var authorization = eval("(" + authResponse.Response + ")");
      var authorizationCode = authorization.authorizationCode;
      //Set the Variable to be accessible in AMPscript
      Variable.SetValue("@authorizationCode",authorizationCode);
    }
  }
  catch(e){
       //LOG THE ERROR INTO A DATA EXTENSION
  }
</script>


THE 3RD AND 2ND CONTENT BLOCK WILL BE HIDDEN TO THE MARKETERS. THIS ENCAPUSALTION MECHANISM WILL BENEFITS BOTH THE DEVELOPERS AND THE MARKETERS. NEITHER THE MARKETERS WILL BE OVERWHELMED WITH SO MANY CODE BLOCKS INSIDE EMAIL NOR THE DEVELOPERS HAVE TO WORRY IF THE MARKETERS WOULD OMIT OR  ADD SOME SYNTAX ERRORS INTO THE CODE DURING HTML EMAIL DESIGN. 




Comments

Most Viewed

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Understanding Transactional Messaging

Preference Center Demystified


Knowledge Article

Popular Posts

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Understanding Transactional Messaging

Preference Center Demystified

Journey Builder REST API Documentation

Share with Friends

Disclaimer:

The information provided on this technical blog is for general informational purposes only. As a SFMC (Salesforce Marketing Cloud) Technical Architect, I strive to offer accurate and up-to-date content related to SFMC and its associated technologies. However, please note that technology is constantly evolving, and the information provided may become outdated or inaccurate over time.

The content published on this blog represents my personal views and experiences as a SFMC Technical Architect and does not necessarily reflect the official views or opinions of any organization or employer I may be affiliated with.

While I make every effort to ensure the accuracy and reliability of the information presented, I cannot guarantee its completeness, suitability, or applicability to your specific circumstances. Therefore, it is essential to verify any information provided and make your own independent assessments or seek professional advice if needed.

Furthermore, any actions taken based on the information provided on this blog are at your own risk. I shall not be held liable for any damages, losses, or inconveniences arising from the use of the information presented here.

Please keep in mind that SFMC and its associated technologies are complex and require technical expertise for proper implementation and management. It is recommended to consult with qualified professionals or official SFMC documentation for comprehensive guidance.

Finally, please note that any product or company names mentioned on this blog are trademarks or registered trademarks of their respective owners. The mention of these trademarks or registered trademarks does not imply any endorsement or affiliation with the blog.

By accessing and using this blog, you agree to the terms of this disclaimer. If you do not agree with any part of this disclaimer, please refrain from using this blog.