|
1 | | -<a href="/masterclasses/" class="c-highlight c-highlight--small c-highlight--ribbon">Arrange a Masterclass</a> |
| 1 | +<a href="/masterclasses/" class="c-highlight c-highlight--small c-highlight--ribbon" id=jsRibbon>Arrange a Masterclass</a> |
| 2 | + |
| 3 | +<script> |
| 4 | +(() => { |
| 5 | + |
| 6 | + const ribbonVariants = [ |
| 7 | + { href: '/masterclasses/', text: 'Arrange a Masterclass' }, |
| 8 | + { href: '/sentinel/', text: 'Sentinel: Your Web-Performance Watchman' }, |
| 9 | + { href: '/performance-audits/#fix-it-fast', text: 'Suffering? Fix it Fast!' }, |
| 10 | + ]; |
| 11 | + |
| 12 | + const getVariantIndex = () => { |
| 13 | + const stored = localStorage.getItem('ribbonVariant'); |
| 14 | + const len = ribbonVariants.length; |
| 15 | + |
| 16 | + if (stored !== null) { |
| 17 | + const n = Number(stored); |
| 18 | + if (Number.isInteger(n) && n >= 0 && n < len) { |
| 19 | + return n; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + const i = Math.floor(Math.random() * len); |
| 24 | + localStorage.setItem('ribbonVariant', i); |
| 25 | + return i; |
| 26 | + }; |
| 27 | + |
| 28 | + const i = getVariantIndex(); |
| 29 | + const { href, text } = ribbonVariants[i]; |
| 30 | + const ribbon = document.querySelector('#jsRibbon'); |
| 31 | + |
| 32 | + if (!ribbon) return; |
| 33 | + |
| 34 | + ribbon.href = href; |
| 35 | + ribbon.textContent = text; |
| 36 | + |
| 37 | + // Send the variant and any clicks to SpeedCurve. |
| 38 | + window.LUX?.addData?.('ribbonVariant', String(i + 1)); |
| 39 | + ribbon.addEventListener('click', () => { |
| 40 | + window.LUX?.addData?.('ribbonClicked', true); |
| 41 | + }); |
| 42 | + |
| 43 | + |
| 44 | +})(); |
| 45 | +</script> |
0 commit comments