I would like to be able to redirect a custom Everwebinar confirmation page (on my domain) visitor to a specific URL at a given date and time that is contained in a confirmation page URL.
The confirmation page URL looks like this:
https://website.com/pagename?preview_theme_id=2151207349?wj_lead_email=email@outlook.com&wj_lead_first_name=FirstName&wj_lead_last_name=LastName&wj_lead_phone_country_code=&wj_lead_phone_number=&wj_lead_unique_link_live_room=https://event.webinarjam.com/go/live/1/k6znqu2twiyznhp42&wj_event_ts=1658918700&wj_event_tz=Europe/London&wj_next_event_date=Wednesday, 24 August 2022&wj_next_event_time=2:00 PM&wj_next_event_timezone=London GMT +1
A simple javascript redirect would be suitable as long as the redirect date, time and URL are all pulled from the confirmation page URL above as each visitor will have a unique URL.
Thank you in advance for your help.
CodePudding user response:
Firstly, it should be noted that the confirmation page URL you gave as an example contains two question marks, which is not valid. This may be a typo, but there should only be one question mark before the URL search parameters, with all search parameters being separated by an ampersand (&).
That being said, there area several methods available to get the values of the URL search parameters and then redirect based on the date/time provided in the URL. The main thing used here is URLSearchParams()
, which allows you to get an object that contains all of the search parameters available. From there, the wj_event_ts is a timestamp that can be used to compare dates/times.
For this example I will use the URL you provided, but if this JavaScript is being run on that confirmation page, I have commented out how to grab the current URL instead.
// If run on the actual confirmation page, use:
// let currentURL = window.location.href;
let currentURL = new URL("https://website.com/pagename?preview_theme_id=2151207349&[email protected]&wj_lead_first_name=FirstName&wj_lead_last_name=LastName&wj_lead_phone_country_code=&wj_lead_phone_number=&wj_lead_unique_link_live_room=https://event.webinarjam.com/go/live/1/k6znqu2twiyznhp42&wj_event_ts=1658918700&wj_event_tz=Europe/London&wj_next_event_date=Wednesday, 24 August 2022&wj_next_event_time=2:00 PM&wj_next_event_timezone=London GMT +1"),
searchParams = new URLSearchParams(currentURL.search),
nextEventDate = new Date(`${searchParams.get("wj_next_event_date")} ${searchParams.get("wj_next_event_time")} ${searchParams.get("wj_next_event_timezone").substr(searchParams.get("wj_next_event_timezone").indexOf("GMT"))}`);
if(Date.now() >= searchParams.get("wj_event_ts")*1000) {
// It is currently past the date in the URL
console.log("Redirecting... Current Event");
//window.location.href = searchParams.get("wj_lead_unique_link_live_room");
}
// If you want to use the next_event_date value instead, use this section
if(Date.now() >= nextEventDate.getTime()) {
console.log("Redirecting... Next Event");
//window.location.href = searchParams.get("wj_lead_unique_link_live_room");
}
EDIT It looks like you have multiple dates in the URL and it was not specified which date/time you would like to use. I have added another commented out section to use the next_event_date value instead of the event_date timestamp.
CodePudding user response:
I used another method of getting the URL parameters and that worked.
const queryString = window.location.search;
console.log(queryString);
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('wj_event_ts')) {
if(Date.now() >= urlParams.get('wj_event_ts')*1000) {
// It is currently past the date in the URL
console.log('Redirecting... Current Event');
window.location.href = urlParams.get('wj_lead_unique_link_live_room');
}
}