Add parameter to every link in delivery from variables
Hi all,
I'm quite new to ACC, so I hope I'm not doing a mistake here which it to obvious...
We have a requirement to add a URL parameter to every link within an email delivery. The parameter is called "campaignId" and it's value should be set on each delivery and then appended to all links in the delivery (with the same value for all links).
So what I tried was the following:
- Set the parameter value as variable "campaignId" in each campaign
- Add the following typology rule:
- Rule type: control
- Phase: After targeting
- Execution order: 50
- Code:
var campaignId = delivery.variables._var[0].stringValue;
if(campaignId !== 'undefined' && campaignId.length > 0){
var deliveryUrlsLength = delivery.content.html.urlConfig.url.length;
// Loop through all URLs
for (var i = 0; i < deliveryUrlsLength; i++){
var urlSource = delivery.content.html.urlConfig.url[i].source;
if(urlSource !== 'undefined' && urlSource.length > 0){
var appendChar = "?";
// Check if the URL Source already contains at least one parameter
if(urlSource.indexOf("?") > 0){
appendChar = "&";
}
//Add the campaignId to the urlSource
delivery.content.html.urlConfig.url[i].source = urlSource + appendChar + "campaignId=" + campaignId;
delivery.content.html.urlConfig.url[i].withParams = true;
delivery.content.html.urlConfig.url[i].modified = true;
logInfo("Appended campaignId to link: " + delivery.content.html.urlConfig.url[i].source);
}
}
}
return true;
Analyze runs fine and the logInfo messages look fine as well. When sending the mails, links are rewritten for targeting, but when clicking the links, the campaignId parameter is not appended.
Any hints on what I'm doing wrong? Is this the correct approach at all?
Thanks for your input!
BR
Sebastian

