Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions dist/blog.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/blog.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/forms/sniffEmail.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trackEvent } from '../utils/amplitude';

export function SniffEmailForAmplitude() {
const interval = setInterval(() => {
const inputs = document.querySelectorAll('input[type=email]');
Expand Down Expand Up @@ -25,7 +27,7 @@ function sniffEmail(inputs) {
return;
}
lastFire = input.value;
amplitude.track('emailInput', { email: input.value, formId });
trackEvent('emailInput', { email: input.value, formId });
}, 3000);
input.addEventListener('input', (ev) => {
if (ev.target.value === lastFire) {
Expand Down
7 changes: 4 additions & 3 deletions src/tracking/amplitude.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { SniffEmailForAmplitude } from '../forms/sniffEmail';
import { trackEvent } from '../utils/amplitude';

export function initAmplitude() {
SniffEmailForAmplitude();
function amplitudeTrack(anchorTag, trackTitle) {
return () => {
amplitude.track(trackTitle, {
trackEvent(trackTitle, {
href: window.location.href,
location: anchorTag.dataset.analyticsLocation,
});
Expand Down Expand Up @@ -39,7 +40,7 @@ export function initAmplitude() {
return;
}
const durationInSeconds = Math.round(new Date().getTime() - timeStartedOnPage.getTime()) / 1000;
amplitude.track('TimeOnPage', {
trackEvent('TimeOnPage', {
duration: `${Math.round(durationInSeconds)}`,
minutes: `${Math.round(durationInSeconds / 60)}`,
pathname,
Expand Down Expand Up @@ -69,7 +70,7 @@ export function initAmplitude() {
window.addEventListener('beforeunload', () => {
const { pathname } = window.location;
trackTimeOnPage(pathname);
amplitude.track('MaxScrollPercentage', { maxScroll, pathname });
trackEvent('MaxScrollPercentage', { maxScroll, pathname });
return undefined;
});
}
70 changes: 33 additions & 37 deletions src/tracking/experiment.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import { waitUntil } from '../utils/wait';
import { Experiment } from '@amplitude/experiment-js-client';

import { waitUntil } from '../utils/wait';

export function initExperiment() {
async function experimentCode() {
try {
const isProd = new URL(window.location.href).host === 'modular-prod-dev.webflow.io';
const apiKey = isProd
? 'client-ejPfaOrUEtTflNBKKrNtLWx5IB1QbAmy'
: 'client-fhQfFdzMgOCoCAWmoV0W8KvnbhFe2dUu';
const experiment = Experiment.initializeWithAmplitudeAnalytics(apiKey);
await experiment.fetch();
Object.entries(experiment.variants.getAll()).forEach(([key, val]) => {
if (val.payload) {
experiment.exposure(key);
const hideStr = val.payload.hide
? `.${val.payload.hide} { display: none !important; }\n`
: '';
const showStr = val.payload.hide
? `.${val.payload.show} { display: flex !important; }`
: '';
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = hideStr + showStr;
document.getElementsByTagName('head')[0].appendChild(style);
}
});
} catch (e) {}
if (document.querySelector('.section_hp-hero')) {
document.querySelector('.section_hp-hero').style.opacity = 1;
}
async function runExperiment() {
if (!window.amplitude) return;
const isProd = new URL(window.location.href).host === 'modular-prod-dev.webflow.io';
const apiKey = isProd
? 'client-ejPfaOrUEtTflNBKKrNtLWx5IB1QbAmy'
: 'client-fhQfFdzMgOCoCAWmoV0W8KvnbhFe2dUu';
const experiment = Experiment.initializeWithAmplitudeAnalytics(apiKey);
await experiment.fetch();
Object.entries(experiment.variants.getAll()).forEach(([key, val]) => {
if (val.payload) {
experiment.exposure(key);
const hideStr = val.payload.hide
? `.${val.payload.hide} { display: none !important; }\n`
: '';
const showStr = val.payload.hide
? `.${val.payload.show} { display: flex !important; }`
: '';
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = hideStr + showStr;
document.getElementsByTagName('head')[0].appendChild(style);
}
});
}

function revealHero() {
document.querySelector('.section_hp-hero')?.style.setProperty('opacity', '1');
}

waitUntil(() => window.amplitude).then(() => {
const isProd = location.href.indexOf('www.modular.com') !== 0;
const sessionReplayTracking = window.sessionReplay.plugin({ sampleRate: isProd ? 0.1 : 0 });
window.amplitude.add(sessionReplayTracking);
window.amplitude.init(
isProd ? '3878a0571d1575870a7d0a5f7e644d23' : 'd8bf208ebdc1b1000d38da8b826a74c4'
);
experimentCode();
});
waitUntil(() => window.amplitude, 150) // ~2.2s cap instead of ~15s
.then(runExperiment)
.catch(() => undefined)
.finally(revealHero);
}
3 changes: 3 additions & 0 deletions src/utils/amplitude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function trackEvent(name, properties) {
window.amplitude?.track(name, properties);
}
Loading