We have recently faced the following challenge, our goal was simple:
- Users in a specific LDAP organization should see a specific HCEC homepage.
- All other users should be redirected to the global “My Communities” page.
HCL Connections Engangement Center (HCEC) offers the Homepage Personalization feature for redirection of the users based on certain LDAP values. This is quite handy, but, per design it only allows redirecting users to HCEC pages. Therefore it is not possible to add a URL of the “My Communities” page to the ruleset and to redirect some users there, as this page is not an HCEC page.
So, I crafted a provisory solution “on the fly”, until we came up with a better one.
My initial solution used an HTML meta refresh directive for the client redirect, which was added to a HCEC HTML-Widget code.
So anytime a user would land on https://connections.domain.com/xcc/main (HCEC Main Page), who as per Homepage Personalization ruleset was redirected to a HCEC page containing the HTML-Widget, the HTML code using HTML meta refresh directive would redirect the user to the “My Communities” (https://connections.domain.com/communities/service/html/allmycommunities) page.
This solution is not optimal for multiple reasons, but mainly because the user would see the HCEC page containing the HTML-Widgets for a second or two before being redirected to the “My Communities” page. Nevertheless the customer liked it, and we never got the time to search for a better one.
A few months later I discovered that some modern browsers would not honor this directive anymore, making this method unreliable. For example, in Firefox the redirection failed often.
So I tried building a similar solution using HCEC Homepage Personalization rules, a simple JavaScript file instead of HCEC HTML-Widget, and the HCL Connections Customizer.
I could’ve used the already present HCEC custom.js file, but decided against it, as it is overwritten by default after every HCEC update, and with JS code already present in it, it would not be easy to troubleshoot if issues arise. In addition to that, it didn’t offer any noticable performance gains.
The Problem in Detail #
The core issue was the unreliability of the old HTML-based redirect. When a user loaded the HCEC Main Page, the personalization rule would serve them a HCEC page containing an HTML meta refresh directive. This directive would often not work, leading to a poor user experience where users were “stuck” on the page containing just the HTML directive.
The Solution #
I replaced the HCEC HTML widget containing the HTML refresh directive with a JavaScript.
Step 1: Create an Intermediate “Stub” Page #
Create a new HCEC page you want to use for this cause. This is just an Intermediate “Stub” page, so it does not need any content. As the page is seen by the user for about a second before being redirected, I’ve added the Title “Redirecting…”. We will also use this title in the JavaScript code later.
Step 2: Configure the HCEC Personalization Ruleset #
Integrate the page created in Step 1 into the Homepage Personalization ruleset.
For example, let’s say, if a user is a member of the “ORG1” LDAP organization, then these users should be redirected to the HCEC page for ORG1, all other users should be redirected to the “My Communities” page.
Step 3: Deploy the JavaScript via Customizer #
Finally, I deployed the following JavaScript globally using the HCL Connections Customizer.
1. The JavaScript (new_redirect.js)
This tiny script is loaded on every Connections page, but it only does one thing: it checks the title of the current page. If the title matches our stub page’s title, it immediately fires the redirect.
// new_redirect.js
(function () {
// Define the URL to detect and the redirect target
const targetTitle = "Redirecting...";
const redirectUrl = "https://connections.domain.com/communities/service/html/allmycommunities";
// Get the current page title
const currentTitle = document.title;
// Check if the current URL matches the target
if (currentTitle === targetTitle) {
window.location.replace(redirectUrl);
}
})();
2. The Customizer Application
I’ve placed this new_redirect.js file on the NFS share used for HCL Connections Component Pack, into the customization directory, for example: <nfs_server>/pv-connections/customizations/redirect/new_redirect.js.
Then, I created a new Customizer application to load this script for all users. JSON code of the HCL Connections Customizer Application:
{
"name": "Default Redirection to My Communities",
"title": "Default Redirection to My Communities",
"description": "Default Redirection to My Communities, for all users which are not redirected to a specific HCEC page as per HCEC ruleset.",
"services": ["Customizer"],
"state": "disabled",
"extensions": [{
"name": "hclsoftware.labservices.redirect.app",
"type": "com.ibm.customizer.ui",
"payload": {
"include-files": [
"redirect/new_redirect.js"
]
},
"path": "global",
"state": "disabled"
}]
}
Notice: Make sure to enable the application when you are ready to commence testing.
The Result: A Faster, Reliable Experience #
By implementing this solution, we achieved two major benefits:
100% Reliability: For now the redirect now works perfectly for all users, regardless of their browser.
Increased Speed: We observed that the JavaScript redirect is noticeably faster than the HTML directive method, getting users to their “My Communities” page with less delay.
This pattern of using an HCEC Homepage Personalization rules to segment users, a “stub” page as a trigger, and a Customizer-deployed script to perform an action is incredibly flexible. The only drawback is, that when redirecting users to non-HCEC pages, as we are doing here, the users will see the “stub” page for a second or two before being redirected.
I hope this helps.