Find your coffee
How do you take your coffee?
Find your coffee
What kind of coffee drinker are you?
Find your coffee
Do you have a coffee grinder?
One more thing
How do you brew?
Finding your perfect coffee…
'
+ '
'
+ '';
}
function renderResults(primary, secondary, sp, secondarySp, decafSp, ratingData) {
var ga = grindAnswer();
/* ── Options from live product data ── */
var sizeIdx = sp ? sp.options.findIndex(function(o) { return o.name.toLowerCase().includes('size'); }) : -1;
var grindIdx = sp ? sp.options.findIndex(function(o) { return o.name.toLowerCase().includes('grind'); }) : -1;
var allSizes = (sp && sizeIdx >= 0) ? sp.options[sizeIdx].values : [];
var allGrinds = (sp && grindIdx >= 0) ? sp.options[grindIdx].values : [];
var defaultSize = sp ? defaultSizeFor(sp) : null;
var grindSearch = GRIND_SEARCH[ga] || 'whole';
var defaultGrind = allGrinds.find(function(g) { return norm(g).includes(norm(grindSearch)); }) || allGrinds[0];
/* Initial variant */
var initVariant = sp ? findVariantByAnswer(sp, defaultSize, ga) : null;
var variantId = initVariant ? initVariant.id : null;
/* ── Product image ── */
var imgSrc = null;
if (sp && sp.media && sp.media[0] && sp.media[0].src) {
imgSrc = sp.media[0].src;
} else if (sp && sp.featured_image) {
imgSrc = String(sp.featured_image);
if (imgSrc.indexOf('//') === 0) imgSrc = 'https:' + imgSrc;
}
var imageHTML = imgSrc
? '' + esc(product.name) + '
' + '' + esc(product.tagline) + '
' + 'View →' + 'Size
' + sizePills + '
Grind
' + grindPills + '
'
+ '$' + (subPrice / 100).toFixed(2) + ''
+ '' + fullFmt + ''
+ '
'
+ 'Delivered every 6 weeks
'; } else if (primary.subscription && subPrice && subPrice !== fullPrice) { var subFmt = '$' + (subPrice / 100).toFixed(2); var saveFmt = '$' + ((fullPrice - subPrice) / 100).toFixed(2); priceHTML = ''
+ '
';
} else {
priceHTML = '' + subFmt + ' on subscription (Save ' + saveFmt + ')
' + '' + fullFmt + ' one-time
' + '' + fullFmt + '
'; } } /* ── Track result shown ── */ trackEvent('quiz_result', { quiz_name: 'coffee_finder', product_name: primary.name, product_handle: primary.handle, q1: state.q1, q2: state.q2, q3: state.q3, q4: state.q4 || null, }); /* ── CTAs — all link to product page with UTM attribution ── */ var variantParam = variantId ? '?variant=' + variantId + '&utm_source=quiz&utm_medium=onsite' : '?utm_source=quiz&utm_medium=onsite'; var baseUrl = '/products/' + primary.handle; var ctaLabel = primary.handle === PRODUCTS.blinddate.handle ? 'Subscribe Now →' : 'Shop Now →'; var ctaHTML = ''
+ '' + ctaLabel + ''
+ '
';
/* ── Suggestion cards ── */
var showDecaf = primary.handle !== PRODUCTS.decaf.handle
&& secondary.handle !== PRODUCTS.decaf.handle;
var suggestionsHTML = ''
+ '
';
/* ── Render ── */
resultCard.innerHTML =
imageHTML
+ 'Also worth exploring
' + ''
+ buildCard(secondary, secondarySp)
+ (showDecaf ? buildCard(PRODUCTS.decaf, decafSp) : '')
+ '
'
+ 'Here\'s what we\'d suggest
' + '' + esc(primary.name) + '
' + ratingHTML + bdBadgeHTML + '' + esc(primary.tagline) + '
' + '' + esc(primary.desc) + '
' + selectorsHTML + priceHTML + ctaHTML + suggestionsHTML + ''; if (sp) attachPills(sp, primary, defaultGrind); /* Track CTA click */ var shopBtn = document.getElementById('gooShopBtn'); if (shopBtn) { shopBtn.addEventListener('click', function() { trackEvent('quiz_cta_click', { quiz_name: 'coffee_finder', product_name: primary.name, product_handle: primary.handle, cta_label: this.textContent.trim(), }); }); } var restartBtn = document.getElementById('gooRestart'); if (restartBtn) restartBtn.addEventListener('click', restart); } /* ── PILL INTERACTION ─────────────────────────────────────────────── */ function attachPills(sp, primary, initGrind) { var currentSize = null; var currentGrind = initGrind || null; var activeSizePill = document.querySelector('#gooSizePills .goo-quiz__pill--active'); var activeGrindPill = document.querySelector('#gooGrindPills .goo-quiz__pill--active'); if (activeSizePill) currentSize = activeSizePill.dataset.val; if (activeGrindPill) currentGrind = activeGrindPill.dataset.val; function syncVariant() { var variant = findVariantByOptions(sp, currentSize, currentGrind) || sp.variants[0]; if (!variant) return; /* Update shop link */ var shopBtn = document.getElementById('gooShopBtn'); if (shopBtn) shopBtn.href='/products/' + primary.handle + '?variant=' + variant.id + '&utm_source=quiz&utm_medium=onsite'; /* Update prices */ var fullPrice = variant.price; var newSubPrice = null; if (sp.selling_plan_groups && sp.selling_plan_groups[0]) { var adj = sp.selling_plan_groups[0].selling_plans[0].price_adjustments[0]; newSubPrice = adj.value_type === 'price' ? adj.value : Math.round(fullPrice * (1 - adj.value / 100)); } var subPriceEl = document.getElementById('gooSubPrice'); var fullPriceEl = document.getElementById('gooFullPrice'); var saveAmtEl = document.getElementById('gooSaveAmt'); var simplePriceEl = document.getElementById('gooPrice'); if (subPriceEl && newSubPrice) subPriceEl.textContent = '$' + (newSubPrice / 100).toFixed(2); if (fullPriceEl) fullPriceEl.textContent = '$' + (fullPrice / 100).toFixed(2); if (saveAmtEl && newSubPrice) saveAmtEl.textContent = '(Save $' + ((fullPrice - newSubPrice) / 100).toFixed(2) + ')'; if (simplePriceEl) simplePriceEl.textContent = '$' + (fullPrice / 100).toFixed(2); } document.querySelectorAll('#gooResultCard .goo-quiz__pill').forEach(function(pill) { pill.addEventListener('click', function() { var type = this.dataset.type; var val = this.dataset.val; var containerId = type === 'size' ? 'gooSizePills' : 'gooGrindPills'; document.querySelectorAll('#' + containerId + ' .goo-quiz__pill') .forEach(function(p) { p.classList.remove('goo-quiz__pill--active'); }); this.classList.add('goo-quiz__pill--active'); if (type === 'size') currentSize = val; if (type === 'grind') currentGrind = val; syncVariant(); }); }); } /* ── RESTART ──────────────────────────────────────────────────────── */ function restart() { state = { q1: null, q2: null, q3: null, q4: null, step: 1 }; document.querySelectorAll('.goo-quiz__option') .forEach(function(b) { b.classList.remove('goo-quiz__option--selected'); }); if (dot4) dot4.style.display = 'none'; var progress = document.getElementById('gooProgress'); if (progress) progress.style.display = ''; document.getElementById('goo-coffee-quiz').classList.remove('goo-quiz--results'); showScreen(1); updateDots(1); } })();