Skip to main content

Optimizely

Optimizely – Slot Swapping Bookmarklet

With this solution, if you use the query string to push you to your slot, you can use your bindings for your live domain to view any of your multiple sites from your single instance.

So….What is a Bookmarklet?

A Bookmarklet is simply a bookmark that has JavaScript in it.

For instance, in the most complicated Bookmarklet, to accomplish what we’re doing, we need to apply the following logic from within a bookmark:

  1. Determine if a query string already exists in the URL
    • This helps us determine if we append with a ? or a &…unless it already exists
  2. If so, is that query string the one we are going to use?
    • we don’t want to add the same query string multiple times
  3. If the query string doesn’t exist, append it on.
    • ?x-ms-routing-name=
  4. If the query string does exist, toggle the keywords
    • Toggle between Self/Slot

 

You can view this article over on my blog website.

In the beginning of this month (August 2021), I saw a blog post that absolutely blew my mind. There is a query string that will allow you to view your Optimizely DXP Slot with your live slot domain name. I had an idea to make this even easier…..CREATE A BOOKMARKLET!

This solves an issue that I faced not too long ago, since you cannot give custom domain names to the DXP Slots. If you have a multi-site instance, and you want to be able to do some spot-checks and functionality tests in the DXP Slot, the only option that you really have is to rebind the slot URL to be the primary URL for the specific site. This is not ideal when the instance has a lot of sites.

With this solution, if you use the query string to push you to your slot, you can use your bindings for your live domain to view any of your multiple sites from your single instance.

So….What is a Bookmarklet?

A Bookmarklet is simply a bookmark that has JavaScript in it.

For instance, in the most complicated Bookmarklet, to accomplish what we’re doing, we need to apply the following logic from within a bookmark:

  1. Determine if a query string already exists in the URL
    • This helps us determine if we append with a ? or a &…unless it already exists
  2. If so, is that query string the one we are going to use?
    • we don’t want to add the same query string multiple times
  3. If the query string doesn’t exist, append it on.
    • ?x-ms-routing-name=
  4. If the query string does exist, toggle the keywords
    • Toggle between Self/Slot

 

You can view this article over on my blog website.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.