Where to add Sourcetag in Email Delivery when sending targeted e-mails through Adobe Campaign classic | Community
Skip to main content
Level 4
February 2, 2025
Solved

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

  • February 2, 2025
  • 2 replies
  • 2308 views

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 

Best answer by ccg1706

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

 


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

 

 

 

2 replies

ccg1706
Community Advisor
Community Advisor
February 2, 2025

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.

<--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

Shruti1Author
Level 4
February 4, 2025

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

ccg1706
Community Advisor
Community Advisor
February 6, 2025

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

Shruti1Author
Level 4
February 4, 2025

 

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 

ccg1706
Community Advisor
Community Advisor
February 5, 2025

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

Level 4
February 5, 2025

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

 


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