Skip to main content

How to track email clicks to 3rd party domains with Salesforce Marketing Cloud

Here are the steps necessary to be able to track clicks in Marketing Cloud emails where the SalesWings tracking script cannot be added.

Pauline from SalesWings avatar
Written by Pauline from SalesWings
Updated yesterday

When looking to track and score email clicks, we distinguish between 2 situations:

1) A click going to a website or landing page which you own, and is tracked with our website tracking script

This can be easily achieved. Make sure that the landing page has our website tracking script installed, and that you are using UTM / campaign parameters in your email links. Based on the UTM parameters, you can then score these link clicks, and report around them using tags.

2) A click going to a third party website or page that you can not track with our website tracking script (for example: PDF's, Youtube.com, partner sites, LinkedIn, etc)

This requires the setup of landing pages, where our website tracking script can be run, which will then redirect the visitor after the click to the final web page where they are sent to.

Step 1 | Create Marketing Cloud Cloud Page

  • In Salesforce Marketing Cloud, create a new Cloud Page.

Step 2 | Add SalesWings tracking script directly to your Cloud Page

Option 1: Use the standard SalesWings tracking script from your cockpit settings page

  • Fetch the SalesWings tracking JavaScript from the SalesWings cockpit settings

  • In the html head section of the Cloud Page, insert the SalesWings tracking JavaScript

Option 2: Use Google Tag Manager to insert the SalesWings tracking script

  • In the html header of the Cloud Page, place the Google Tag Manager code snippet

    • Important: The GTM container must of course contain the SalesWings tracking script.
      ​

Example GTM code (don't use):

<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-XXXXXX');</script><!-- End Google Tag Manager -->

Step 3 | Add the below redirect script into the footer of your Cloud Page

  • In the html footer of the Cloud Page, please add the following Javascript code snippet:

<!-- Redirect Script -->
<script>
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
var redirect_url = getUrlParameter('url')
setTimeout(function(){
window.location.href = redirect_url;
}, 500); //redirect time, in miliseconds
</script>
<!-- End Redirect Script -->

Step 4 | Update the links going to 3rd party pages in your emails as follows

  • The links in your emails that go to 3rd party pages that you want to be tracked, first have to be pointing to this Marketing Cloud Cloud page so that we can identify the click.

  • In the links, you need to you need to pass the final destination URL as an argument. The function will only encode strings where the URL is suffixed by a ? character.

  • Please place the following url in the href tag of the link that needs to be tracked:

https://subdomain.domain.com/sw-redirect?url=%%=UrlEncode('<insert_url_to_track_here>')=%%

Example:

  • The URL you need to use as a hyperlink in your email should look like this:

https://subdomain.domain.com/sw-redirect?url=%%=UrlEncode('https://www.youtube.com/music-videos')=%%


​

πŸ“ IMPORTANT NOTES:

  • The code will not track if the user has javascript disabled in their browser

  • Every Cloud Page view counts as 1 SuperMessage towards the Salesforce Marketing Cloud SuperMessage limit (limit different for each Customer)

Did this answer your question?