Many organizations, especially banks, insurance companies and other organizations that value trust highly are very careful about how links are formatted in emails that are being sent out. The key is that links need to be “safe” which in essence means they need to have the correct domain. For example company Contoso, this means that the domain needs to end with “contoso.com” and could for instance be “forms.contoso.com” or something similar. However, there is currently no way to create “branded” links in CI-J and this feature was deprioritized and removed from Release wave 2 2024. I (and a some customers of mine) are hoping it will be coming soon. In the meantime, I have been considering what options there are. Here is one, with a simple webpage that just redirects to some other webpage based on some parameters.

You can try it here with this url:

https://powerplatform.se/1061-2?url=https%3A//crmkonsulterna.se&param1=value1&param2=value2

And here is the html code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redirecting...</title>
    <!--
        This webpage will redirect the browser to the url indicated in the query string paramater "url", forward all other query string parameters
        and also track the webusage in Dynamics 365 CIJ
        Ex. url (file located in c:\temp): file:///C:/temp/redirect.html?url=https%3A//skandia.se&param1=value1&param2=value2
    -->
    <script>
        // Function to get query string parameters
        function getQueryParam(name) {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get(name);
        }

        // Function to get all query string parameters except 'url'
        function getOtherQueryParams() {
            const urlParams = new URLSearchParams(window.location.search);
            let params = [];
            urlParams.forEach((value, key) => {
                if (key !== 'url') {
                    params.push(`${key}=${encodeURIComponent(value)}`);
                }
            });
            return params.join('&');
        }

        // Redirect to the URL specified in the 'url' query parameter
        window.onload = function () {
            const targetUrl = getQueryParam('url');
            if (targetUrl) {
                // Basic validation to ensure it's a valid URL
                try {
                    const validatedUrl = new URL(targetUrl);

                    // Get other query parameters and append them to the target URL
                    const otherParams = getOtherQueryParams();
                    if (otherParams) {
                        validatedUrl.search = validatedUrl.search ? validatedUrl.search + '&' + otherParams : '?' + otherParams;
                    }

                    // Perform the redirect
                    window.location.href = validatedUrl.href;
                } catch (e) {
                    console.error('Invalid URL:', targetUrl);
                    document.body.innerHTML = '<h1>Invalid URL</h1><p>Please provide a valid URL as a query parameter.</p>';
                }
            } else {
                document.body.innerHTML = '<h1>No URL Provided</h1><p>Add a "url" query parameter to redirect.</p>';
            }
        }
    </script>
</head>
<body>
    <p>Redirecting...</p>
</body>
</html>

The code simply parses the parameter url and redirects to this url including all other query string parameters. This is important as that will maintain any UTM tags that were added.

The point is hence to place this webpage on any page internally at the company, for ex. https://contoso.com/redirect.html and then call it with the parameters indicated like
https://contoso.com/redirect.html?url=https%3A//crmkonsulterna.se&param1=value1&param2=value2

In CI-J this means that you either manually have to assemble these url:s or create some function, preferably connected to the ribbon to easier be able to add this redirect url to the email.

Tracking

As we need to make sure that the URL is not using the built in tracking in CI-J, using the normal button functionality of “Tracking” needs to be switched off, as the tracking functionality uses Microsoft redirect pages and hence break the typical “no link outside our domains”-policy.

We do need to track anyway and there are two ways that I can see that off the top of my head will achieve this:

  • Using webtracking
  • Using custom triggers

Webtracking is, at the time of writing this article, a preview functionality, and we might hence be a bit hesitant in trying it out. If you want to, there is a setting switch for it under settings in CI-J. Then reload the page and click on “Web tracking” to get the correct script.

Custom triggers has been around a while and is probably easier to use. Create a custom trigger and get the code snippet for it and add it to the redirect-page. Every time someone hits the redirect page the custom trigger will be called. When using triggers, I would recommend using parameters to forward all relevant data to the journey where you want it.

I hope this helps you or gives you inspiration on how to do something similar!