Titel in CSS Info für Datum: webinar-dynamic-datetime
Titel in CSS Info für Link: webinar-dynamic-link
Code, der in Trackingcode hinzugefügt werden muss:
<!-- Styles for dynamic webinar data -->
<style>
[data-title='webinar-dynamic-datetime']>div {
font-weight: bold;
}
[data-title='webinar-dynamic-link']>div {
font-weight: bold;
}
</style>
<!-- Script that manages dynamic webinar data -->
<script>
function get24hTime(str){
str = String(str).toLowerCase().replace(/\s/g, '');
var has_am = str.indexOf('am') >= 0;
var has_pm = str.indexOf('pm') >= 0;
// first strip off the am/pm, leave it either hour or hour:minute
str = str.replace('am', '').replace('pm', '');
// if hour, convert to hour:00
if (str.indexOf(':') < 0) str = str + ':00';
// now it's hour:minute
// we add am/pm back if striped out before
if (has_am) str += ' am';
if (has_pm) str += ' pm';
// now its either hour:minute, or hour:minute am/pm
// put it in a date object, it will convert to 24 hours format for us
var d = new Date("1/1/2011 " + str);
// make hours and minutes double digits
var doubleDigits = function(n){
return (parseInt(n) < 10) ? "0" + n : String(n);
};
return doubleDigits(d.getHours()) + ':' + doubleDigits(d.getMinutes());
}
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};
// if query string exists
if (queryString) {
// stuff after # is not part of query string, so get rid of it
queryString = queryString.split('#')[0];
// split our query string into its component parts
var arr = queryString.split('&');
for (var i = 0; i < arr.length; i++) {
// separate the keys and the values
var a = arr[i].split('=');
// set parameter name and value (use 'true' if empty)
var paramName = a[0];
var paramValue = typeof(a[1]) === 'undefined' ? true : a[1];
// (optional) keep case consistent
paramName = paramName.toLowerCase();
if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();
// if the paramName ends with square brackets, e.g. colors[] or colors[2]
if (paramName.match(/\[(\d+)?\]$/)) {
// create key if it doesn't exist
var key = paramName.replace(/\[(\d+)?\]/, '');
if (!obj[key]) obj[key] = [];
// if it's an indexed array e.g. colors[2]
if (paramName.match(/\[\d+\]$/)) {
// get the index value and add the entry at the appropriate position
var index = /\[(\d+)\]/.exec(paramName)[1];
obj[key][index] = paramValue;
} else {
// otherwise add the value to the end of the array
obj[key].push(paramValue);
}
} else {
// we're dealing with a string
if (!obj[paramName]) {
// if it doesn't exist, create property
obj[paramName] = paramValue;
} else if (obj[paramName] && typeof obj[paramName] === 'string') {
// if property does exist and it's a string, convert it to an array
obj[paramName] = [obj[paramName]];
obj[paramName].push(paramValue);
} else {
// otherwise add the property
obj[paramName].push(paramValue);
}
}
}
}
return obj;
};
function capitalize(s){
return s.toLowerCase().replace( /\b./g, function(a){ return a.toUpperCase(); } );
};
function insertDynamic(){
if(getAllUrlParams().wj_next_event_time){
var webinar_date = capitalize(decodeURIComponent(getAllUrlParams().wj_next_event_date).replace(/\+/g," ")).replace(/(\d\d?\s)/g,'$&\.').replace(/\s\./,'\. ');
var webinar_time = decodeURIComponent(getAllUrlParams().wj_next_event_time).replace(/\+/g," ");
var webinar_link = decodeURIComponent(getAllUrlParams().wj_lead_unique_link_live_room);
document.querySelector("[data-title='webinar-dynamic-datetime']>div").textContent = webinar_date+", um "+get24hTime(webinar_time)+" Uhr";
document.querySelector("[data-title='webinar-dynamic-link']>div").innerHTML = '<a target="_blank" href="'+webinar_link+'">'+ webinar_link + '</a>' ;
}
}
document.addEventListener("DOMContentLoaded", insertDynamic);
</script>