Expand my Community achievements bar.

Create typology rule that checks that the source html content contains a specific phrase/Personalisation block

Avatar

Level 2

Hi,

 

I'm trying to create a typology rule that checks whether or not the Source HTML Content of an email contains a specific Personalisation block, and will block send if not included. e.g. Personalisation block = <%@ include view='PBTest' %>

 

I've tried a few different ways but no joy so far and JS experience is low.

 

Has anyone managed to do this before please?

 

Thanks

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 4

Hi @waynea40432451 ,

Below is a code which we use to check the custom Unsubscrition URL is present or not in delivery before sending by using Typogoloy rule. Hence you can use the same to check the PB block or any content inside the delivery.

Below is the code which we use for URL check:

var sg = new StringGroup("nms:core");

function checkUrlOptout(urlList, bHtml) {
  var bOptOut = false;
  var isUrlMatch = false;

  // Dummy unsubscribe URLs replacing actual client URLs
  var DummyClient1UnsubURL = "https://www.dummyclient1.com/unsubscribe.html";
  var DummyClient2UnsubURL = "https://www.dummyclient2.com/unsubscribe.html";
  var DummyClient1UnsubURLNew = "Content to check 1";
  var DummyClient2UnsubURLNew = "Content to check 2";
  for (var i = 0; i < urlList.length; i++) {
    if (urlList[i].trackingType == 4) {          
      bOptOut = true;
      logWarning(urlList[i].source);
      if (urlList[i].source == DummyClient1UnsubURL || urlList[i].source == DummyClient2UnsubURL || urlList[i].source == DummyClient1UnsubURLNew || urlList[i].source == DummyClient2UnsubURLNew) {
          isUrlMatch = true; 
          logWarning("Unsubscribe URL for dummy clients is present");     
          break;
      } else {
          logError("Unsubscribe URL for dummy clients is not present. Please use the correct Unsub Personalization Block.");
      }
    }
  }
  
  if (!bOptOut) {
    if (bHtml) {      
      logError(sg.missingOptoutHtml());
    } else {
      logError(sg.missingOptoutText());
    }
  }
  
  return true;
}

function typologyRule() {
  var bSuccessText = true;
  var bSuccessHtml = true;
  
  if (!delivery.tracking.enabled) {
    return true; // nothing to do if tracking is disabled
  }
  
  if (delivery.content.text.source !== "") {
    bSuccessText = checkUrlOptout(delivery.content.text.urlConfig.url, 0);
  }
  
  if (delivery.content.html.source !== "") {
    bSuccessHtml = checkUrlOptout(delivery.content.html.urlConfig.url, 1);
  }
  
  if (bSuccessText && bSuccessHtml) {
    return true;
  }
  
  return false;
}

return typologyRule();

 
By using the same above logic I have created the below code to check the content inside email delivery before send I have not tested it but I believe it should work.

var sg = new StringGroup("nms:core");

function checkTextPresence(content, isHtml) {
  var textFound = false;
  
  // Define the text you want to search for (e.g., a disclaimer or keyword)
  var requiredText = "Insert your required text here"; // Replace with the text to search for
  
  // Check if the required text exists in the content
  if (content.indexOf(requiredText) !== -1) {
    textFound = true;
    logInfo("Required text '" + requiredText + "' is present in the " + (isHtml ? "HTML" : "Text") + " content.");
  } else {
    logError("Required text '" + requiredText + "' is not present in the " + (isHtml ? "HTML" : "Text") + " content. Please include it.");
  }
  
  return textFound;
}

function typologyRule() {
  var bSuccessText = true;
  var bSuccessHtml = true;
  
  // Check text content if it exists
  if (delivery.content.text.source !== "") {
    bSuccessText = checkTextPresence(delivery.content.text.source, 0);
  }
  
  // Check HTML content if it exists
  if (delivery.content.html.source !== "") {
    bSuccessHtml = checkTextPresence(delivery.content.html.source, 1);
  }
  
  // Return true only if the required text is found in both (or either, depending on your logic)
  if (bSuccessText && bSuccessHtml) {
    return true;
  }
  
  return false;
}

return typologyRule();


Let me know if this helps.

Thanks

Sushant Trimukhe

Avatar

Administrator

Hi @waynea40432451,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know. In case the given solution was helpful, then kindly choose it as the 'Correct Reply'.

Thanks!



Sukrity Wadhwa