Understanding the Issue
A community member asked about using %%linkname%% in a code snippet block that is then referenced in WAC. The issue arises because %%linkname%% only renders within the WAC configuration itself, and not in the code snippet block.
For example, if you have a WAC configuration like this: utm_content=%%=TreatAsContent(ContentBlockById(736082))=%%, and a code snippet block (736082) containing %%linkname%%, the result will be ?utm_content=%%linkname%%, which is not the desired output.
Root Cause
The root cause of this issue is that personalization strings like %%linkname%% are not designed to work within code snippet blocks referenced in WAC. Instead, they are meant to be used directly in the WAC configuration.
Solution
To resolve this issue, you can use an ampscript variable set in the code, rather than relying on personalization strings. This approach provides more control and flexibility when working with WAC.
ampscript example
%%[ var @linkName ]%%
%%=IIF(IndexOf("%%linkname%%","%")>0,"no_alias_set","%%linkname%%")=%%
This code sets an ampscript variable @linkName and uses the IIF function to check if the link name is set. If it is not set, it defaults to “no_alias_set”.
Best Practices
Heads up: When working with WAC and ampscript, it is essential to test your code thoroughly to ensure it is working as expected.
Checklist
- Use ampscript variables instead of personalization strings
- Test your code thoroughly
- Use the IIF function to check if the link name is set
- Default to a fallback value if the link name is not set
- Use the TreatAsContent function to render the code snippet block
- Verify the WAC configuration is correct
- Test the utm_content parameter to ensure it is working as expected
Frequently Asked Questions
What is the purpose of the IIF function in this code?
The IIF function is used to check if the link name is set, and if not, it defaults to a fallback value.
Can I use personalization strings in the code snippet block?
No, personalization strings like %%linkname%% are not designed to work within code snippet blocks referenced in WAC.
How do I test my WAC configuration?
You can test your WAC configuration by sending a test email and verifying the utm_content parameter is working as expected.
What is the purpose of the TreatAsContent function?
The TreatAsContent function is used to render the code snippet block as content.
Can I use this approach for other WAC configurations?
Yes, this approach can be used for other WAC configurations that require the use of ampscript variables and the IIF function.
Need help shipping this in production?
Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.