Skip to main content
(Question originally posted on Trailblazer (https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000E9U5f), where it was suggested I post here, instead)

My organization has a set of branded content blocks to be used as templates in Marketing Cloud content builder. Because updates are sometimes made to these, I am trying to programmatically use these blocks to display content from an XML feed, to ensure the most recent template block is being used.    

 

I am able to use ContentBlockByID and replace all of the placeholder content, but there seems to be an issue when replacing any links. The links get replaced fine in the Preview and Test view, but the links in the delivered test email still direct to the placeholder link in the original block, rather than the link that should have replaced it.   

 

I think this has something to do with the link wrapping (https://help.salesforce.com/s/articleView?id=sf.mc_es_link_tracking.htm&type=5) happening before the link is able to get replaced. (The organization uses custom branded links, if that makes any difference) The link replacement does work when I uncheck "Track Clicks" in the Test Send settings.  

 

Is something like this possible to do, without turning off click tracking? Is there an alternate solution that might work better?   

 

Every method I have tried I have done in both AMPScript and SSJS. It seems that even replacing the link in the same line the block is called doesn't do the trick. 

AMPScript

Set @newEvent = Replace(ContentBlockbyID("245740"), @placeholderLink, @replacementLink)

SSJS

var newEvent = Platform.Function.ContentBlockByID("245740").replace(RegExp((placeholderLink), "g"), repalcementLink.substring(1, link.length-1));

I have also tried locating the wrapped link to replace it, but that doesn't work either. I am able to write the link in the email to confirm I located the correct link to replace, but it doesn't get replaced, and the same tracking link is still there. (This method works in the preview, but not in the delivered test email)

// locate href to find index position of the link

var hrefIndex = newBlock.indexOf('href="') + 6;

// find the next quote after the href to locate end of link

var hrefEndIndex = newBlock.indexOf('"', hrefIndex);

var linkToReplace = newBlock.substring(hrefIndex, hrefEndIndex)

Write("link to replace: <br />");

Write(linkToReplace);

Write("<br />new link: <br />");

Write(link);

// remove quotes from around new link var, when replacing

newBlock = newBlock.replace(RegExp((linkToReplace)), "g"), link.substring(1, link.length-1));

Using substring to concatenate the link and content leads to a broken link, even in the Preview and Test view

newBlock = newBlock.substring(0, hrefIndex).concat(link.substring(1, link.length-1), newBlock.substring(hrefEndIndex));

1 risposta
  1. 24 apr 2022, 04:43
    I'm ready to utilize ContentBlockByID and supplant all of the placeholder content, yet there is, by all accounts, an issue while supplanting any connections. The connections get supplanted fine in the preview and test views, yet the connections in the conveyed test email actually direct to (https://styloss.com/) the placeholder interface in the first square, instead of the connection that ought to have supplanted it.

    I think this has something to do with the connection wrapping occurring before the connection can get supplanted. (The association utilizes exclusively marked joins if that has any effect.) The connection substitution takes care of business when I uncheck "Track Clicks" in the Test Send settings. Is something like this conceivable to do, without switching off click following? Is there another arrangement that could work better?
0/9000