Automatically add referral tag to URLs with Clipboard Fusion

jessehouwing profile image Jesse Houwing Originally published at jessehouwing.net on ・3 min read

Automatically add referral tag to URLs with Clipboard Fusion

Recently Microsoft introduced the Docs & Learn program. You, the MVP and content creator, get a unique identifier to add to any url linking to a number of Microsoft websites, and they automatically track the engagement you generate.

There's one small but, you need to add an identifier to every link you post. In my case to every link on:

  • This blog,
  • StackOverflow,
  • Microsoft forums,
  • GitHub wikis
  • Presentations shared on SlideShare
  • Etc.

And of course this technique works with any affiliate link program, so you can adapt it for the Amazon PartnerNet and many other sites as well.

While it isn't rocket science to edit a link, it can be tricky business. You have to juggle the ?, # and & just right and in the right order.

For example, to add my unique identifier to the following link:


You can make quite a few mistakes:

❌ https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019#generated-code?WT.mc_id=DOP-MVP-5001511
❌ https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019#generated-code&WT.mc_id=DOP-MVP-5001511
❌ https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?WT.mc_id=DOP-MVP-5001511?view=vs-2019#generated-code

The correct way to add the referral code is:

🎉 https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?WT.mc_id=DOP-MVP-5001511&view=vs-2019#generated-code
🎉 https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019&WT.mc_id=DOP-MVP-5001511#generated-code

Of course we all know this, right?! But still, it would be much nicer if one could automate this. To do that I turned to a trusty old tool called Clipboard Fusion. It's a nifty little tool that sits in your Windows task tray and manages the contents of your clipboard. One of it's feature is, that it can run a C# snippet on a trigger, so I set out to create such little snippet of magic, to automatically add my identifier to every suitable link I put on my clipboard.

using System;
using System.Web;

public static class ClipboardFusionHelper
    // Put your ID below
    public static string ID = "DOP-MVP-5001511";

    public static string[] docsAndLearnChampionDomains = { 

        public static string ProcessText(string text)

                Uri x = new Uri(text, UriKind.Absolute);

                bool match = false;

                foreach (var domain in docsAndLearnChampionDomains)
                    var y = new Uri("https://" + domain, UriKind.Absolute);
                    if (string.Equals(x.Host, y.Host, StringComparison.OrdinalIgnoreCase) 
                        && x.AbsolutePath.StartsWith(y.AbsolutePath, StringComparison.OrdinalIgnoreCase))
                        match = true;

                if (match)
                    var uriBuilder = new UriBuilder(x);
                    var query = HttpUtility.ParseQueryString(uriBuilder.Query);
                    query["WT.mc_id"] = ID;
                    uriBuilder.Query = query.ToString();
                    return uriBuilder.Uri.AbsoluteUri;
            catch (UriFormatException) { }
            return text;

You can download the macro from here and use the Import option to add it to your instance of Clipboard Fusion.

Step-by-step adding the Macro to Clipboard Fusion.

Automatically add referral tag to URLs with Clipboard Fusion
Import the Macro into Clipboard Fusion

And then configure it as a new trigger on the Triggers tab:

Automatically add referral tag to URLs with Clipboard Fusion
Run the macro when the Trigger Command is received

Now every link you copy that matches the configured list of domains and paths will automatically be updated with your MVP ID before pasting it into your email, blog, forum answer or PowerPoint presentation.

Banner photo by ton.volz used under Creative Commons.

Posted on by:

jessehouwing profile

Jesse Houwing


I love good coffee, meaning strong, dark espresso! Regular Expressions are like word-puzzles to me, as are LINQ queries. I take pictures everywhere I go. Husband of 1, father of 2.


Editor guide