Top Posts
ClickDimensions – Middle Ware
PowerPlatform / Dataverse – Five Layers of Security
Solution Framework Fundamentals
Solution Strategy
FLOW – The Workflow Replacement
Power Automate: Your UI testing companion – Part...
Updates Delayed
Build the Future
Learn more about me…
Power Automate Patterns: Scottish Summit 2020
Dave Burrell
  • Home
  • Power Automate
  • Power Platform
  • D365
  • Solution Architecture
  • Lifestyle
  • About Me
  • Contact Me
AzureDynamics 365

ClickDimensions – Middle Ware

by Dave Burrell 14th January 2019
by Dave Burrell 14th January 2019
0FacebookTwitterLinkedinRedditWhatsappEmail
4.1K

This is an expansion on my previous post about the ClickDimensions Cookie Challenge. ClickDimensions is an excellent addon for Dynamics 365 though when it comes to form capture, it lacks what I feel is a fundamental function. Out of the box when a form is submitted the system is only capable of redirecting the end user to either a success or failure page, while this works well for contact us forms it is not as suitable for the likes of a whitepaper download where you want to redirect the user to a specific page based on the context of the form.

To resolve this issue, I created an Azure web app middleware that sits between the website form and ClickDimensions which allows a logic layer and provides far more control on where to redirect the user.

The middleware effectively acts as a buffer between the website and ClickDimensions. By intercepting the response from ClickDimensions, we can control where the user is redirected to.

In this example code, I have used a hidden field on the form to allow the website to pass over the redirect URL to the service. The other option would be to code the redirect logic directly into the Azure App. The method used here give you far more control as it is easier to pass the URL as part of the web form opposed to coding the logic into the application.

Another area to note is that this code has a honeypot field built in to reduce the risk of spam. On each of the form, a hidden field should be created called hp. A real end user will never even know the field exists, but a robot will pick this up as a field to be filled in. This reduces the risk of a bot attack dramatically. I would however still recommend implementing recaptcha.

I have included a link to the sample code on GitHub. The area to note is the mechanism to capture the response from ClickDimensions. For this I have used the stream code below:

        private string PostToServer(string FormCaptureURL, string PostData)
        {
            try
            {
                string serverResponse = String.Empty;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormCaptureURL);
                // Set the Method property of the request to POST.
                request.Method = "POST";
                // Create POST data and convert it to a byte array.
                byte[] byteArray = Encoding.UTF8.GetBytes(PostData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded";
                // set referer
                request.Referer = Properties.Settings.Default.Referrer;
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                serverResponse = reader.ReadToEnd();
                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();

                return serverResponse;
            }
            catch
            {
                throw;
            }
        }

Effectively this reads the website response from ClickDimensions as if it was a user on the browser. The redirect contains a single line of text of either success or failure which the stream code reads and redirects accordingly.

Click to open GitHub project.

AzureClickDimensions
0 FacebookTwitterLinkedinRedditWhatsappEmail

Leave a Comment Cancel Reply

Save my name, email, and website in this browser for the next time I comment.

Dave Burrell

Hey! I am Dave Burrell a Power Platform Solution Architect. I am an evangelist for all things Power Platform and love nothing more than a #LowCodeNoCode implementation.

previous post
Dynamics 365 April ’19 – Key Dates
next post
MSE and Insideview: The end is nigh

You may also like

ClickDimensions Cookie Challenge

2nd January 2019

About Me

About Me

Power Platform Evangelist

Hey! I am Dave Burrell a Power Platform Solution Architect. I am an evangelist for all things Power Platform and love nothing more than a #LowCodeNoCode implementation.

Lets be Social!

Facebook Twitter Instagram Linkedin Youtube Email

Quote

Revolutions begin with Community!

Recent Posts

  • Power Automate: Protect your Flow Run History 28th September 2021
  • Building the Future: Power Platform for Girl Guiding 22nd September 2021
  • Build the Future 18th August 2021
  • Power Platform Community – Resources! 12th August 2021
  • PowerFX – A Game Changer! 18th July 2021
  • Facebook
  • Twitter
  • Instagram
  • Linkedin
  • Youtube
  • Email

@2021 - All Right Reserved. Designed and Developed by Dave Burrell


Back To Top
Dave Burrell
  • Home
  • Power Automate
  • Power Platform
  • D365
  • Solution Architecture
  • Lifestyle
  • About Me
  • Contact Me
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok