Rokt UX Helper - Troubleshooting
This guide addresses common issues that might arise when implementing the Rokt UX Helper library and provides solutions.
Common Issues
Experiences Not Rendering
If your experiences aren't appearing on the page:
-
Element Selectors Don't Match: Ensure that the
targetElementSelectorin your experience payload matches the ID or class of yourrokt-layout-viewelement.// Check the plugin configuration in your response
console.log(experienceData.plugins.map(plugin => plugin.plugin.targetElementSelector));
// Make sure these selectors match your elements
console.log(document.querySelector('rokt-layout-view').id); // Should match one of the selectors -
Empty or Invalid Payload: Verify that your experience payload is valid and contains plugins.
// Validate the payload structure
if (!experienceData || !experienceData.plugins || experienceData.plugins.length === 0) {
console.error('No valid experience data available');
} -
Custom Element Not Registered: Ensure the custom elements are properly registered.
// Check if the element is registered
console.log(!!customElements.get('rokt-layout-view'));
// Register manually if needed
import { registerCustomElements } from '@rokt/ux-helper-web';
registerCustomElements(); -
Multiple Overlay Elements: Only the first
rokt-layout-viewwith therender-overlayattribute will receive overlay experiences. Check your implementation if you have multiple overlay elements.
CDN Issues
If you're facing issues with loading the library from CDN:
-
Incorrect CDN Path: The correct paths for the library are:
<!-- CommonJS format (for direct browser usage) -->
<script src="https://cdn.jsdelivr.net/npm/@rokt/ux-helper-web/dist/index.cjs"></script>
<!-- ESM format (for modern applications) -->
<script type="module">
import * as RoktUXHelper from 'https://cdn.jsdelivr.net/npm/@rokt/ux-helper-web/dist/index.mjs';
</script> -
Version Issues: If a version is giving you trouble, try specifying an exact version:
<script src="https://cdn.jsdelivr.net/npm/@rokt/ux-helper-web@0.1.5/dist/index.cjs"></script> -
CORS Issues: If you're experiencing CORS errors, ensure your server is configured to allow the CDN domain.
-
Network Issues: Check your browser's network tab to verify the CDN files are being loaded correctly.
Console Errors
"Failed to construct 'CustomElement'"
If you see errors related to constructing custom elements:
Uncaught DOMException: Failed to construct 'CustomElement': The result must not have attributes
This typically occurs in older browsers or with polyfills. Ensure you're using the latest version of the library and consider adding polyfills for older browsers:
<script src="https://unpkg.com/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@rokt/ux-helper-web/dist/index.cjs"></script>
"Cannot read property 'renderExperiences' of null"
This error occurs when trying to call methods on an element that doesn't exist in the DOM:
Uncaught TypeError: Cannot read property 'renderExperiences' of null
Ensure the element exists before trying to use it:
const roktElement = document.getElementById('rokt-layout-placeholder');
if (roktElement) {
roktElement.renderExperiences(experienceData);
} else {
console.error('Element #rokt-layout-placeholder not found in DOM');
}
Layout Issues
"Warning: Multiple overlay plugins detected"
If you see a warning about multiple overlay plugins:
WARNING: Multiple overlay plugins detected. Only rendering the first one.
This means you have multiple plugins targeting the body selector. Only the first one will be rendered. If you need to render multiple overlays, consider using different placement strategies.
Experiences Not Visible But Present in DOM
If experiences are rendered in the DOM but not visible:
-
Check for CSS Issues: Inspect the element and verify no CSS is hiding the content:
/* Add this temporarily to debug */
rokt-layout-view {
border: 1px solid red;
min-height: 50px;
}
Event Handling Issues
Events Not Firing
If you're not receiving events:
-
Event Listeners Attached Too Late: Ensure event listeners are attached before rendering experiences:
// Correct order
roktElement.addEventListener('RoktUXEvent', handleUXEvent);
roktElement.addEventListener('RoktPlatformEvent', handlePlatformEvent);
roktElement.renderExperiences(experienceData); -
Event Bubbling Issues: Check if events are being stopped from propagating in a parent element:
// Use capturing phase to intercept events earlier
document.addEventListener('RoktUXEvent', handleUXEvent, true);
document.addEventListener('RoktPlatformEvent', handlePlatformEvent, true);
Platform Events Not Being Processed
If Rokt platform events aren't being correctly processed:
-
Incorrect Event Payload: Ensure you're forwarding the complete event payload:
roktElement.addEventListener('RoktPlatformEvent', (event) => {
// Send the ENTIRE detail object, don't modify it
sendToBackend(event.detail);
}); -
Network Issues: Verify that events are being sent to the correct endpoint with proper authentication.
React Specific Issues
TypeScript Errors
If you're getting TypeScript errors with React:
-
Missing Custom Element Declaration: Ensure you've declared the custom element:
declare global {
namespace JSX {
interface IntrinsicElements {
"rokt-layout-view": React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
ref?: React.RefObject<HTMLElement>;
},
HTMLElement
>;
}
}
} -
Type Casting Issues: Use proper type casting for events:
const handleUXEvent = (event: Event) => {
// Cast to CustomEvent to access detail property
const customEvent = event as CustomEvent;
console.log(customEvent.detail);
};
Ref Issues
If you're having issues with React refs:
// Use correct ref type and access pattern
const roktRef = useRef<HTMLElement & {
renderExperiences: (data: any) => void;
close: () => void;
}>(null);
// Later in your code
if (roktRef.current) {
roktRef.current.renderExperiences(data);
}