Expand my Community achievements bar.

SOLVED

Where to add Sourcetag in Email Delivery when sending targeted e-mails through Adobe Campaign classic

Avatar

Level 5

Hi team,

I have a requirement where we have to add sourcetags in Email Deliverywhen sending targeted e-mails through Adobe Campaign Classic

 

please help me to understand where we can add sourcetags in Email Deliverywhen sending targeted e-mails through Adobe Campaign Classic

 

Please let me know wheere and how  to add it  to all the links to the website in order to Analytics to track it 

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi @DishaSharma,

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Ensure the email content is accessible
if (message && message.content && message.content.html && message.content.html.source) {
    var htmlContent = message.content.html.source; // Get the email HTML content

    // Convert email HTML to lowercase to avoid case sensitivity issues
    var modifiedContent = htmlContent.replace(/href="([^"]*?)"/gi, function(match, url) {
        if (url.indexOf("source=") === -1) { // Check if 'source=' already exists
            var separator = url.indexOf("?") > -1 ? "&" : "?";
            return 'href="' + url + separator + "source=" + sourceTag + '"';
        }
        return match; // Return unchanged if 'source=' is already present
    });

    // Log modified content for debugging
    logInfo("Updated Email HTML: " + modifiedContent.substring(0, 500)); // Log first 500 characters to avoid truncation

    // Update the email content with the modified version
    message.content.html.source = modifiedContent;
}

Try with these, additionally run it in a workflow before using it in a typology rule. If again fails you will have to open  a ticket to support sharing the error and your typology rule details.

 

Regards, 

Celia

 

 

 

View solution in original post

22 Replies

Avatar

Level 8

Hi @Shruti1,

 

There are different ways to add source tags:

 

-You can add them manually inside your html content within the delivery you are sending. Example:<a href=" yourlink?utm_source=AdobeCampaign&utm_medium=email&utm_campaign=SpringSale">

- As manually is a waste of time, you can enable tracking on all URLS inside the mail go to properties tab.

ccg1706_0-1738481558307.png

<--Image taken for Adobe Documentation>
-You can also create a typology rule where you add Java Script to add UTM parameters for every link. A possible JS could be this:

var content = delivery.content.html.source; //grabs the content of the HTML and stores it in the variable content 
content = content.replace(/href="(https:\/\/www\.example\.com[^"]*)"/g, 'href="$1&utm_source=AdobeCampaign&utm_medium=email"');//Replace example with the link you want to put.

 

Test which method is better for you but I'll recommend the second one.

Additionally I leave you a useful doc link:Tracking messages 

Kind regards, 

Celia

Avatar

Level 5

hi @celia thanks for your reply

but i need to create typology rule

that loops over all the url in delivery and add the source tag

Source tag=

E00040S3000D99908

 

could you please suggest correct typology rule fort his

Avatar

Level 8

Hi @Shruti1,

 

Under Adminisitration-Campaign Management-Typologies you can create a typology rule applying the following JavaScript

 

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Function to check if a URL already contains the source tag
function appendSourceTag(url) {
    var separator = url.includes("?") ? "&" : "?"; // Determine if ? or & is needed
    return url + separator + "source=" + sourceTag;
}

// Loop through all URLs in the delivery
var delivery = delivery.content.html.source; // Get the HTML content
var modifiedContent = delivery.replace(/href="([^"]+)"/g, function(match, url) {
    // Append source tag if not already present
    if (!url.includes("source=")) {
        return 'href="' + appendSourceTag(url) + '"';
    }
    return match; // If the source already exists, keep it as it is
});

// Update the content of the delivery
delivery.content.html.source = modifiedContent;

 

Let me know if it helps.

 

Regards,

Celia

Avatar

Level 4

Hello @ccg1706

I am getting below error while applying this typlogy rule mentioned above

please help me with the correct code for this typology rule

06/02/2025 18:01:07 DLV-490000 An error occurred while executing rule 'NewTypoRule'. Please ask the platform administrator 'Adobe Inc.' to check syntax and validity of this rule.

 

 

Avatar

Level 8

Hi @DishaSharma,

 

Managing delivery.content.html.source as an object and string sometimes brings problems.

 

Try with this new JS, and let me know how it goes.

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Ensure the delivery content is accessible
if (delivery && delivery.content && delivery.content.html && delivery.content.html.source) {
    var htmlContent = delivery.content.html.source; // Get the email HTML content

    // Replace all href links, adding the source tag if not already present
    var modifiedContent = htmlContent.replace(/href="([^"]+)"/g, function(match, url) {
        if (!url.includes("source=")) {
            var separator = url.includes("?") ? "&" : "?";
            return 'href="' + url + separator + "source=" + sourceTag + '"';
        }
        return match; // Keep the URL unchanged if source already exists
    });

    // Update the email content with the modified version
    delivery.content.html.source = modifiedContent;
}

 

 

Regards, 

Celia

Avatar

Level 4

Hello@ccg1706

I am again facing same error,, please help me with the correct code, this is urgent requirement for me and i need to finish it anyhow ..hope u und,,,please help

 

07/02/2025 09:58:09 XML-110018 Error while parsing XML string ''
07/02/2025 09:58:09 (1:1) : invalid document structure
07/02/2025 09:58:09 DLV-490000 An error occurred while executing rule 'NewRule'. Please ask the platform administrator 'Adobe Inc.' to check syntax and validity of this rule.

Avatar

Level 8

Hi @DishaSharma,

 

Try with this version, using message.cntent.html.source.

 

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Ensure the email content is accessible
if (message && message.content && message.content.html && message.content.html.source) {
    var htmlContent = message.content.html.source; // Get the email HTML content

    // Replace all href links, adding the source tag if not already present
    var modifiedContent = htmlContent.replace(/href="([^"]+)"/g, function(match, url) {
        if (!url.includes("source=")) {
            var separator = url.includes("?") ? "&" : "?";
            return 'href="' + url + separator + "source=" + sourceTag + '"';
        }
        return match; // Keep the URL unchanged if source already exists
    });

    // Update the email content with the modified version
    message.content.html.source = modifiedContent;
}

If you still having errors let me know.

 

Regards, 

Celia

Avatar

Level 4

I am again receiving the same error:

DLV-490000 An error occurred while executing rule 'NewRule'. Please ask the platform administrator 'Adobe Inc.' to check syntax and validity of this rule.

please help to send me correct code for this...please

Avatar

Level 8

Hi @DishaSharma,

 

Try with these:

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Ensure the email content is accessible
if (message && message.content && message.content.html) {
    var htmlContent = message.content.html.source; // Get the email HTML content

    if (htmlContent) {
        // Use simple string manipulation instead of regex
        var urls = htmlContent.match(/href="([^"]+)"/g); // Find all href links
        
        if (urls) {
            for (var i = 0; i < urls.length; i++) {
                var originalUrl = urls[i].substring(6, urls[i].length - 1); // Extract URL
                if (originalUrl.indexOf("source=") === -1) { // If 'source=' is not already present
                    var separator = originalUrl.indexOf("?") > -1 ? "&" : "?";
                    var newUrl = 'href="' + originalUrl + separator + "source=" + sourceTag + '"';
                    htmlContent = htmlContent.replace(urls[i], newUrl);
                }
            }
        }

        // Update the email content with the modified version
        message.content.html.source = htmlContent;
    }

Additonally, make sure you check that message.content,html.source is writable and try to add also logInfo(htmlContent); before updating message.content.html.source to see if the URL is modified correctly.

 

Regards, 

Celia

Avatar

Level 4

Hello @ccg1706 

Thanks for your reply always ... .however I tried the code you mentioned

but still getting the same error

please help me with correct code please

 

Avatar

Correct answer by
Level 8

Hi @DishaSharma,

// Define the source tag
var sourceTag = "E00040S3000D99908";

// Ensure the email content is accessible
if (message && message.content && message.content.html && message.content.html.source) {
    var htmlContent = message.content.html.source; // Get the email HTML content

    // Convert email HTML to lowercase to avoid case sensitivity issues
    var modifiedContent = htmlContent.replace(/href="([^"]*?)"/gi, function(match, url) {
        if (url.indexOf("source=") === -1) { // Check if 'source=' already exists
            var separator = url.indexOf("?") > -1 ? "&" : "?";
            return 'href="' + url + separator + "source=" + sourceTag + '"';
        }
        return match; // Return unchanged if 'source=' is already present
    });

    // Log modified content for debugging
    logInfo("Updated Email HTML: " + modifiedContent.substring(0, 500)); // Log first 500 characters to avoid truncation

    // Update the email content with the modified version
    message.content.html.source = modifiedContent;
}

Try with these, additionally run it in a workflow before using it in a typology rule. If again fails you will have to open  a ticket to support sharing the error and your typology rule details.

 

Regards, 

Celia

 

 

 

Avatar

Level 5

 

Hi team,

I have a requirement where we have to add sourcetags in Email Deliverywhen sending targeted e-mails through Adobe Campaign Classic in click formula 

NmsTracking_ClickFormula

please help me to understand where we can add sourcetags in NmsTracking_ClickFormula under Platform->options

Alternatively, can we create typology rule

that loops over all the URL in delivery and add the as the source tag

-->PLEASE GUIDE ME ON THIS PART

 

Please let me know where and how  to add the source tag to all the urls in email delivery in order to Analytics to track it 

Topics

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

Avatar

Level 8

Hi @Shruti1,

 

It would be more practical, to create a typology rule, cause it is more flexible and allows you to process all URLs dynamically within the email content before sending or you can modify the NmsTracking_Clickormula).

 

Applying JavaScript you can do it, defining the variables and a for to loop trough each link and append the sourcetag.

 

If you need more help, just let me know.

 

Regards,

Celia

Avatar

Level 4

Hello @ccg1706

 

I also need to work on same requirement:

 

I need, to create a typology rule, and which allows you to process all URLs dynamically within the email content before sending

Applying JavaScript you can do it, defining the variables and a for to loop trough each link and append the sourcetag.

my source tag is: For FB: SOURCETAG=C0030P3000A99P0000F0000MCD0

can u help me with the code for typology rule for this please

 

also second method:

where we can modify the NmsTracking_Clickormula, can u give me the code for this NmsTracking_Clickormula-modified with addition of sourcetag

 

 

 

Avatar

Level 8

Hi @DishaSharma,

 

Try with the following codes:

 

For method 1: (typology rule)

//  Time to add that SOURCETAG magic to all URLs in the email before sending 

// Define our special source tag for FB 
var sourcetag = "SOURCETAG=C0030P3000A99P0000F0000MCD0";

// Loop through all the URLs in the email content 
for each (var url in delivery.content.html.links) {
    
    var linkUrl = url.url; // Grab the current URL

    // If it doesn't have a ?, we add one. Otherwise, we slap on an &
    linkUrl += (linkUrl.indexOf("?") === -1) ? "?" + sourcetag : "&" + sourcetag;

    // Update the link with our new fancy tracked version ️
    url.url = linkUrl;
}

// Log the operation 
logInfo(" SOURCETAG successfully added to all URLs in this email. ");

 

For method 2: (Adding Source tag)

//  Let’s make sure our links are tracked when clicked! 

// Grab the original URL (the one without our magic yet)
var url = event.getUrl();

// Our FB source tag 
var sourcetag = "SOURCETAG=C0030P3000A99P0000F0000MCD0";

// Time to make it sparkle 
url += (url.indexOf("?") === -1) ? "?" + sourcetag : "&" + sourcetag;

// Return our beautifully modified URL 
return url;

 

Let me know if you need more assistance.

 

Kind regards,

Celia

 

Avatar

Level 4

hello @ccg1706 

thanks for u reply

below is NmsTracking_ClickFormula:

 

 

<% if( typeof strPurlTrackingServer!="undefined" && strPurlTrackingServer.toString() ) { %><%= strPurlTrackingServer %><% } else { %><%@ include option='NmsTracking_ServerUrl' %><% } %>/r/?id=<%=
type.substr(0, 1) %><% if( typeof(message.id) === 'string' ) { %><%= message.id %><% }
else { %><%= (message.id<0 ? (message.id+4294967296) : message.id).toString(16).toLowerCase() %><% }
%>,<%@ value object="delivery" xpath="@idTracking" %>,<%= escapeUrl("$(urlId)") %>

<%
if (document.mode == "forward")
{
var d = message.getParameter("d")
if( d )
d = d.split(",")
%>&ap_visitorId=<%=message.getParameter("visitorId") != '' ? message.getParameter("visitorId"):0 %>&ap_category=<%= d[0]?d[0]:'' %>&ap_deliveryId=<%=d[1]?parseInt(d[1],16):0%><%
} %><%
if( typeof proposition != "undefined" && proposition.length == undefined )
{ %>&ap_oid=<%= ( proposition.offer.id && proposition.offer.id != 0 ) ? proposition.offer.id : proposition.offer_id %><%
} %>

 

 

could you please help to let me know where exactly i should put the code which u mentioned above..please

awaiting ur reply

Avatar

Level 8

Hi, @DishaSharma:

 

Here you have the complete code:

<% 
if (typeof strPurlTrackingServer != "undefined" && strPurlTrackingServer.toString()) { 
%>
    <%= strPurlTrackingServer %>
<% 
} else { 
%>
    <%@ include option='NmsTracking_ServerUrl' %>
<% 
} 
%>/r/?id=<%= type.substr(0, 1) %>
<% 
if (typeof(message.id) === 'string') { 
%>
    <%= message.id %>
<% 
} else { 
%>
    <%= (message.id < 0 ? (message.id + 4294967296) : message.id).toString(16).toLowerCase() %>
<% 
} 
%>,<%@ value object="delivery" xpath="@idTracking" %>,

<%
var url = escapeUrl("$(urlId)"); 
var sourcetag = "SOURCETAG=C0030P3000A99P0000F0000MCD0";


if (url.indexOf("?") === -1) {
    url += "?" + sourcetag;
} else {
    url += "&" + sourcetag;
}
%>
<%= url %>

<%
if (document.mode == "forward") {
    var d = message.getParameter("d");
    if (d) d = d.split(",");
%>
    &ap_visitorId=<%= message.getParameter("visitorId") != '' ? message.getParameter("visitorId") : 0 %>
    &ap_category=<%= d[0] ? d[0] : '' %>
    &ap_deliveryId=<%= d[1] ? parseInt(d[1], 16) : 0 %>
<%
}
%>

<%
if (typeof proposition != "undefined" && proposition.length == undefined) { 
%>
    &ap_oid=<%= (proposition.offer.id && proposition.offer.id != 0) ? proposition.offer.id : proposition.offer_id %>
<% 
} 
%>

 

Regards, 

Celia

Avatar

Level 4

hello @ccg1706 

I have tried the code which u mentioned but no luck,, i cant see appended source tag in URL of email...

please help me with correct code

 

Avatar

Level 4

Hello@ccg1706

 

I tried this but its not working could you please help me where exaclty after which line of code in NmsTrackingClick formula,

I should add your code

 

//  Let’s make sure our links are tracked when clicked! 

// Grab the original URL (the one without our magic yet)
var url = event.getUrl();

// Our FB source tag 
var sourcetag = "SOURCETAG=C0030P3000A99P0000F0000MCD0";

// Time to make it sparkle 
url += (url.indexOf("?") === -1) ? "?" + sourcetag : "&" + sourcetag;

// Return our beautifully modified URL 
return url;

 

Avatar

Level 5

Hello@ccg1706

Please help me with correct code..