Home > widget-integration > CountdownTimerController
CountdownTimerController class
Controller that manages the countdown timer widget lifecycle.
Handles the full flow: fetching the active campaign from the API, rendering the timer into the DOM, ticking every second, and handling expiration behavior (repeat, disable, or freeze at 00:00:00).
Signature:
export declare class CountdownTimerController
Example
Extend to add analytics tracking when the timer is displayed:
window.boostWidgetIntegration.extend('CountdownTimerController', (CountdownTimerController) => {
return class CustomController extends CountdownTimerController {
async connect(element) {
await super.connect(element);
if (element.style.display !== 'none') {
window.dataLayer?.push({ event: 'countdown_timer_displayed' });
}
}
};
});
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
| |||
|
| |||
|
|
CountdownTimerService |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
|
Bind click and keyboard handlers for the "entire bar clickable" CTA mode. Reads the navigation URL from the | |
|
Initialize the countdown timer on the given DOM element. Fetches the active campaign via the API, then starts the render/tick loop. Hides the element if the API call fails or no campaign matches. | ||
|
Stop the tick interval and release all internal references. Called automatically by . Can also be called directly to clean up without hiding the element. | ||
|
|
Retrieve the Liquid template string for the countdown timer. | |
|
|
Handle timer expiration based on the campaign's | |
|
|
Hide the timer element and destroy the controller. | |
|
|
Inject campaign-specific CSS (colors, fonts, sizes) via JS. | |
|
|
Validate that a URL is safe for navigation. Allows | |
|
|
Perform the initial tick and start the 1-second interval loop. Called once after a campaign is successfully fetched. Runs the first | |
|
|
Render the current time into the DOM via Liquid template. Called once per second by the tick interval. Parses the rendered HTML, replaces the element's children, injects campaign styles, and binds CTA click handlers. | |
|
|
Strip characters that could break out of a CSS value context. Removes | |
|
|
Make the timer element visible by clearing | |
|
|
Clear the running Called by and before restarting the interval in . Override to cancel additional async work tied to the tick lifecycle. | |
|
|
Single tick: calculate remaining time and render or handle expiration. Runs every second via the interval set by . Delegates to when the timer reaches zero, or otherwise. |