Instantly share code, notes, and snippets.
Created
January 22, 2025 15:55
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save andresgallo/5f5309de7d514a7ed52153dcbb7162af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta charset="{{#with charset}}{{this}}{{else}}UTF-8{{/with}}"> | |
{{~#with meta}}{{this}}{{/with~}} | |
{{include "/articlesource/ArticleSource.hbs" this}} | |
<style type="text/css">{{include "/global/Colors.hbs" this}}</style> | |
<style type="text/css">{{include "/global/Typography.hbs" this}}</style> | |
<link data-cssvarsponyfill="true" class="Webpack-css" rel="stylesheet" href="{{cdn "/styleguide/All.min.css"}}"> | |
<link rel="stylesheet" href="https://static.forumcomm.com/css/all.css"> | |
{{~#with extraStyles}}{{this}}{{/with~}} | |
<meta name="viewport" content="{{#with viewport}}{{this}}{{else}}width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=5{{/with}}"> | |
{{~#with title}}<title>{{this}}</title>{{/with~}} | |
{{~#with description}}<meta name="description" content="{{this}}">{{/with~}} | |
{{~#with keywords}}<meta name="keywords" content="{{this}}">{{/with~}} | |
{{~#with canonicalLink}}<link rel="canonical" href="{{this}}">{{/with~}} | |
{{~#with contentId}}<meta name="brightspot.contentId" content="{{this}}">{{/with~}} | |
{{~#with favicons}}{{this}}{{/with}} | |
{{~#with manifestLink}}<link rel="manifest" href="{{this}}">{{/with}} | |
{{~#with feedLink}}{{this}}{{/with~}} | |
{{~#with jsonLinkedData}}<script type="application/ld+json">{{this}}</script>{{/with~}} | |
{{!-- ampLink from brightspot.amp - Provided by ViewModelOverlays --}} | |
{{~#with ampLink}}<link rel="amphtml" href="{{{this}}}">{{/with}} | |
{{!-- Brightspot Meta Tags - Provided by ViewModelOverlays --}} | |
{{!-- CacheControlViewModelOverlay --}} | |
<meta name="brightspot.cached" content="{{#with isCached}}{{this}}{{else}}false{{/with}}"> | |
<script> | |
function getForumCookie(cname) { | |
let name = cname + "="; | |
let decodedCookie = decodeURIComponent(document.cookie); | |
let ca = decodedCookie.split(';'); | |
for(let i = 0; i < ca.length; i++) { | |
let c = ca[i]; | |
while (c.charAt(0) == ' ') { | |
c = c.substring(1); | |
} | |
if (c.indexOf(name) == 0) { | |
return c.substring(name.length, c.length); | |
} | |
} | |
return ""; | |
} | |
function setForumCookie(cname, cvalue, exdays) { | |
const d = new Date(); | |
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); | |
let expires = (exdays !== 0) ? "expires=" + d.toUTCString() + ";" : ""; | |
const hostNameArray = window.location.hostname.split('.') | |
const indexOfWWW = hostNameArray.indexOf('www') | |
if (indexOfWWW > -1) { | |
hostNameArray.splice(indexOfWWW, 1) | |
} | |
var propertyName = hostNameArray[0] | |
var environment = 'production' | |
if (window.location.hostname.includes('qa') || | |
window.location.hostname.includes('uat') || | |
window.location.hostname.includes('localhost') | |
) { | |
environment = 'test' | |
} else if (window.location.hostname.includes('web')) { | |
environment = 'production-other' | |
} | |
if (environment === 'production') { | |
let topLevelDomain = (propertyName === "newscenter1") ? '.tv' : '.com' | |
document.cookie = | |
cname + '=' + cvalue + ';' + expires + | |
'path=/;domain=' + propertyName + topLevelDomain | |
} else { | |
document.cookie = cname + '=' + cvalue + ';' + expires + 'path=/'; | |
} | |
} | |
</script> | |
{{#if chartbeat.0.chartbeatUid}} | |
{{include "/chartbeat/ChartbeatScript.hbs" this}} | |
{{/if}} | |
{{#if (and (eq globalEngageEnabled true) (eq naviga.0.engageEnabled true))}} | |
{{!-- Naviga Engage Loader and Init scripts --}} | |
{{include "/naviga/NavigaEngage.hbs" this}} | |
{{/if}} | |
{{!-- Viafoura OIDC authentication script --}} | |
{{include "/viafoura/Viafoura-authentication.hbs" this}} | |
{{!-- Viafoura general script --}} | |
{{include "/viafoura/Viafoura.hbs" this}} | |
{{#if (eq admiral.0.admiralEnabled true)}} | |
{{include "/admiral/Admiral.hbs" this}} | |
{{/if}} | |
<script src="{{cdn "/styleguide/webcomponents-loader/webcomponents-loader.js"}}"></script> | |
<script> | |
/** | |
This allows us to load the IE polyfills via feature detection so that they do not load | |
needlessly in the browsers that do not need them. It also ensures they are loaded | |
non async so that they load before the rest of our JS. | |
*/ | |
var head = document.getElementsByTagName('head')[0]; | |
if (!window.CSS || !window.CSS.supports || !window.CSS.supports('--fake-var', 0)) { | |
var styleGuideScript = document.createElement('script'); | |
styleGuideScript.setAttribute('src', "{{cdn '/styleguide/util/IEPolyfills.js'}}"); | |
styleGuideScript.setAttribute('type', 'text/javascript'); | |
styleGuideScript.async = false; | |
head.appendChild(styleGuideScript); | |
} | |
</script> | |
<script> | |
window.dataLayer = [] | |
window.paywall = window['paywall'] || [] | |
</script> | |
{{include "/datalayer/datalayer-obj.hbs" this}} | |
<script src="{{cdn "/styleguide/All.min.js"}}" async></script> | |
{{#if (eq googleExtendedAccess.0.googleExtendedAccessEnabled true)}} | |
{{include "/googleextendedaccess/GoogleExtendedAccess.hbs" this}} | |
{{/if}} | |
{{~#with extraScripts}}{{this}}{{/with~}} | |
{{~#with prebidScript}}{{this}}{{/with~}} | |
{{!-- First Entry Campaign script --}} | |
{{include "/firstentrycampaign/FirstEntryCampaign.hbs" this}} | |
<script> | |
var link = document.createElement('link'); | |
link.setAttribute( | |
'href', | |
'//fonts.googleapis.com/css?family={{#with fontSerif}}{{this}}{{else}}Brygada+1918{{/with}}:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700|{{#with fontSansSerif}}{{this}}{{else}}Source+Sans+Pro{{/with}}:300,400,600,700' | |
) | |
var relList = link.relList; | |
if (relList && relList.supports('preload')) { | |
link.setAttribute('as', 'style'); | |
link.setAttribute('rel', 'preload'); | |
link.setAttribute('onload', 'this.rel="stylesheet"'); | |
link.setAttribute('crossorigin', 'anonymous'); | |
} else { | |
link.setAttribute('rel', 'stylesheet'); | |
} | |
head.appendChild(link); | |
</script> | |
<script type="text/javascript"> | |
(function () { | |
function clickEpaper() { | |
let epaperLink = "{{epaperUrl}}"; | |
function redirectToEpaper() { | |
window.location.href = epaperLink; | |
} | |
redirectToEpaper(); | |
} | |
function clickSubscribe(subscribeUrl, offerTitle, clickClass) { | |
offerTitle = offerTitle || ''; | |
clickClass = clickClass || ''; | |
if (getForumCookie('_fcc_utm_campaign') == '') { | |
createCampaignCookie(subscribeUrl, offerTitle); | |
} | |
if (!isNavigaTemplate(subscribeUrl, clickClass)) { | |
window.location.href = updateUrlCampaignParameters(subscribeUrl, clickClass); | |
} | |
} | |
function isNavigaTemplate(url, clickClass) { | |
let subscribeLinks = document.getElementsByClassName('subscribe-button'); | |
for (let i = 0; i < subscribeLinks.length; i++) { | |
if (subscribeLinks[i].href === url) { | |
subscribeLinks[i].setAttribute( | |
'href', | |
updateUrlCampaignParameters(url, clickClass) | |
); | |
return true; | |
} | |
} | |
return false; | |
} | |
// For G2I to work correctly, all three parameters must be present | |
// otherwise the parameters will not be recorded | |
function hasAllParams(queryString) { | |
let hasUtmCampaign = | |
queryString.includes('utm_source') && | |
queryString.includes('utm_medium') && | |
queryString.includes('utm_campaign'); | |
let hasG2iCampaign = | |
queryString.includes('g2i_source') && | |
queryString.includes('g2i_medium') && | |
queryString.includes('g2i_campaign'); | |
return hasUtmCampaign || hasG2iCampaign; | |
} | |
function createCampaignCookie(tempQueryString, offerTitle) { | |
offerTitle = offerTitle || ''; | |
let source = ''; | |
let medium = ''; | |
let campaign = ''; | |
let queryString = tempQueryString | |
.replace('?', '&') | |
.replace('utm_source', 'g2i_source') | |
.replace('utm_medium', 'g2i_medium') | |
.replace('utm_campaign', 'g2i_campaign'); | |
let queryStringParams = queryString.split('&'); | |
for (let i = 0; i < queryStringParams.length; i++) { | |
let tempString = queryStringParams[i]; | |
let tempArr = tempString.split('=') || []; | |
if (tempString.includes('g2i_source') && source === '') { | |
source = '&'.concat('g2i_source=', encodeURIComponent(tempArr[1])); | |
} | |
if (tempString.includes('g2i_medium') && medium === '') { | |
medium = '&'.concat('g2i_medium=', encodeURIComponent(tempArr[1])); | |
} | |
if (tempString.includes('g2i_campaign') && campaign === '') { | |
campaign = '&'.concat('g2i_campaign=', encodeURIComponent(tempArr[1])); | |
} | |
} | |
// Sets the default values for the cookie | |
if (source === '') { | |
source = '&g2i_source=Brightspot'; | |
} | |
if (medium === '' && offerTitle !== '') { | |
if (offerTitle.includes('Print + Digital')) { | |
medium = 'combo'; | |
} else { | |
medium = offerTitle.toLowerCase().replaceAll(' ', '_'); | |
} | |
medium = '&g2i_medium=' + encodeURIComponent(medium); | |
} else if (medium === '') { | |
// ! what should the medium be if the offerTitle is empty? | |
medium = '&g2i_medium=unknown'; | |
} | |
if (campaign === '') { | |
campaign = '&g2i_campaign=no_campaign'; | |
} | |
setForumCookie('_fcc_utm_campaign', source.concat(medium, campaign), 0); | |
} | |
function addReturnUrl(url) { | |
if (!url.includes('returnUrl')) { | |
let returnUrl = ""; | |
let currentUrl = document.location.href; | |
// Determine if the currentUrl already has a returnUrl | |
if (currentUrl.includes("returnUrl")) { | |
returnUrl = currentUrl.split("returnUrl=")[1]; | |
} else if (currentUrl.includes('/subscribe')) { | |
// If on the subscribe page, use the referrer | |
returnUrl = document.referrer; | |
} else { | |
// Otherwise, use the current URL | |
returnUrl = currentUrl; | |
} | |
url = url.concat('&returnUrl=', encodeURIComponent(returnUrl)); | |
} | |
return url; | |
} | |
// Ensures that the URL being passed to it contains all 3 G2I parameters, and adds them if they dont exist | |
function updateUrlCampaignParameters(navigaSubscribeUrl, clickClass) { | |
clickClass = clickClass || ''; | |
navigaSubscribeUrl = navigaSubscribeUrl || ''; | |
let tempUrl = navigaSubscribeUrl; | |
let queryString = navigaSubscribeUrl?.split('?'); | |
let hrefQueryString = queryString.length ? queryString[1] : ''; | |
let campaignCookie = getForumCookie('_fcc_utm_campaign'); | |
// If the URL does not contain any parameters | |
if (hrefQueryString === '') { | |
tempUrl = navigaSubscribeUrl.concat(campaignCookie.replace('&', '?')); | |
if (clickClass === 'Page-header-subscribe') { | |
dataLayer.push({'subscribe_button_url': tempUrl }); | |
} | |
return addReturnUrl(tempUrl); | |
} | |
if (hasAllParams(navigaSubscribeUrl)) { | |
if (clickClass === 'Page-header-subscribe') { | |
dataLayer.push({'subscribe_button_url': navigaSubscribeUrl }); | |
} | |
return addReturnUrl(navigaSubscribeUrl); | |
} else { | |
if (!hrefQueryString.includes('g2i_source')) { | |
tempUrl = tempUrl.concat('&g2i_source=Brightspot'); | |
} else if (!hrefQueryString.includes('g2i_medium')) { | |
tempUrl = tempUrl.concat('&g2i_medium=unknown'); | |
} else if (!hrefQueryString.includes('g2i_campaign')) { | |
tempUrl = tempUrl.concat('&g2i_campaign=no_campaign'); | |
} | |
if (clickClass === 'Page-header-subscribe') { | |
dataLayer.push({'subscribe_button_url': tempUrl }); | |
} | |
return addReturnUrl(tempUrl); | |
} | |
} | |
// Check for query string parameters with campaign codes | |
// and FCC UTM Campaign cookie | |
let queryString = document.location.search; | |
if ( | |
getForumCookie('_fcc_utm_campaign') === '' && | |
queryString !== '' && | |
hasAllParams(queryString) | |
) { | |
createCampaignCookie(queryString); | |
} | |
{{#if (and (eq globalEngageEnabled true) (eq naviga.0.engageEnabled true))}} | |
ensureUserIsSet().then(function(){ | |
if (window?.user.status === 'subscribed') { | |
let ownedSubs = Connext.Storage.GetUserData().OwnedSubscriptions; | |
for (const ownedSub of ownedSubs) { | |
if (ownedSub.PaperCode === 'SLS') { | |
setForumCookie('_fcc_sls_subscribed', true, 0); | |
} | |
} | |
} | |
else { | |
setForumCookie('_fcc_sls_subscribed', false, 0); | |
} | |
}); | |
{{/if}} | |
Object.assign(window, { | |
clickEpaper: clickEpaper, | |
clickSubscribe: clickSubscribe | |
}); | |
})(); | |
</script> | |
<script id="flkty" src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment