Automatically add referral tag to URLs with Clipboard Fusion
Tags: tipsntricks, community, tools
Published: 2020-09-21 20:52:46

---
title: Automatically add referral tag to URLs with Clipboard Fusion
published: true
date: 2020-09-21 12:40:40 UTC
tags: TipsnTricks,Community,Tools
canonical_url: https://jessehouwing.net/automatically-add-referral-tag-to-urls-with-clipboard-fusion/
---

 ![Automatically add referral tag to URLs with Clipboard Fusion](https://jessehouwing.net/content/images/2020/09/3927189226_c05bfc4d94_o.jpg)

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:

```
https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019#generated-code
```

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](https://www.clipboardfusion.com/). 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 = { 
            "docs.microsoft.com",
            "learn.microsoft.com",
            "social.technet.microsoft.com",
            "azure.microsoft.com",
            "techcommunity.microsoft.com",
            "social.msdn.microsoft.com",
            "devblogs.microsoft.com",
            "developer.microsoft.com",
            "channel9.msdn.com",
            "gallery.technet.microsoft.com",
            "cloudblogs.microsoft.com",
            "technet.microsoft.com",
            "docs.azure.cn",
            "www.azure.cn",
            "msdn.microsoft.com",
            "blogs.msdn.microsoft.com",
            "blogs.technet.microsoft.com",
            "microsoft.com/handsonlabs"
        };

        public static string ProcessText(string text)
        {

            try
            {
                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;
                        break;
                    }
                }

                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](https://gist.github.com/jessehouwing/7dd997447d5267b77842f4f5bd5a5996) and use the Import option to add it to your instance of Clipboard Fusion.

<iframe width="612" height="344" src="https://www.youtube.com/embed/6_DbJH3Acg0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Step-by-step adding the Macro to Clipboard Fusion.</figcaption>

![Automatically add referral tag to URLs with Clipboard Fusion](https://jessehouwing.net/content/images/2020/09/image.png)<figcaption>Import the Macro into Clipboard Fusion</figcaption>

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

![Automatically add referral tag to URLs with Clipboard Fusion](https://jessehouwing.net/content/images/2020/09/image-1.png)<figcaption>Run the macro when the Trigger Command is received</figcaption>

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.](https://www.flickr.com/photos/8985837@N08/3927189226/in/photolist-6Z2Sx5-fB6M89-fATPgX-74NX1N-7tr4ux-5qCxqQ-5HeGMe-6YXRFV-ER7AY-Ei4SH6-fEhuya-5RBXFx-aCyqJH-PyG5z9-6Zwtib-e35yZ-ewGQzA-8D5xsF-8Xtyeh-8j8ciT-KEmGVT-21XxpDu-ixJr6G-2j4rigV-6SmdrZ-5u18Ud-4EvLu4-5eFKSw-3VZrWj-81qmKN-PyG4bh-2j3NMie-5KYnSR-PVno72-iBQz3M-5bfgBf-PyG4Tj-26KEbzG-P9oEwU-SUMHjK-7USb9b-6jo7mV-232CJbh-kDYHC-qLNdUp-PpaYZ1-PpaYrC-4Go5jR-2814GsG-296osFp)