utms for everybody

This commit is contained in:
Danny Coates 2019-03-05 12:58:40 -08:00
parent c8ea3a6138
commit 5e04f367c1
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
4 changed files with 57 additions and 2 deletions

View File

@ -106,6 +106,14 @@ export default function(state, emitter) {
}); });
emitter.on('signup-cta', source => { emitter.on('signup-cta', source => {
const query = state.query;
state.user.startAuthFlow(source, {
campaign: query.utm_campaign,
content: query.utm_content,
medium: query.utm_medium,
source: query.utm_source,
term: query.utm_term
});
state.modal = signupDialog(source); state.modal = signupDialog(source);
render(); render();
}); });

View File

@ -16,8 +16,15 @@ export default function initialize(state, emitter) {
} }
emitter.on('DOMContentLoaded', () => { emitter.on('DOMContentLoaded', () => {
// experiment = storage.enrolled[0]; // experiment = storage.enrolled[0];
const query = appState.query;
addEvent('client_visit', { addEvent('client_visit', {
entrypoint: appState.route === '/' ? 'upload' : 'download' entrypoint: appState.route === '/' ? 'upload' : 'download',
referrer: document.referrer,
utm_campaign: query.utm_campaign,
utm_content: query.utm_content,
utm_medium: query.utm_medium,
utm_source: query.utm_source,
utm_term: query.utm_term
}); });
}); });
emitter.on('experiment', experimentEvent); emitter.on('experiment', experimentEvent);

View File

@ -94,6 +94,29 @@ export default class User {
return this.loggedIn ? hashId(this.storage.id) : hashId(anonId); return this.loggedIn ? hashId(this.storage.id) : hashId(anonId);
} }
async startAuthFlow(source, utms = {}) {
try {
const params = new URLSearchParams({
entrypoint: `send-${source}`,
form_type: 'email',
utm_source: utms.source || 'send',
utm_campaign: utms.campaign || 'none'
});
const res = await fetch(
`${this.authConfig.issuer}/metrics-flow?${params.toString()}`
);
const { flowId, flowBeginTime } = await res.json();
this.flowId = flowId;
this.flowBeginTime = flowBeginTime;
this.utms = utms;
} catch (e) {
console.error(e);
this.flowId = null;
this.flowBeginTime = null;
this.utms = null;
}
}
async login(email) { async login(email) {
const state = arrayToB64(crypto.getRandomValues(new Uint8Array(16))); const state = arrayToB64(crypto.getRandomValues(new Uint8Array(16)));
storage.set('oauthState', state); storage.set('oauthState', state);
@ -111,6 +134,17 @@ export default class User {
if (email) { if (email) {
options.email = email; options.email = email;
} }
if (this.flowId && this.flowBeginTime) {
options.flow_id = this.flowId;
options.flow_begin_time = this.flowBeginTime;
}
if (this.utms) {
options.utm_campaign = this.utms.campaign || 'none';
options.utm_content = this.utms.content || 'none';
options.utm_medium = this.utms.medium || 'none';
options.utm_source = this.utms.source || 'send';
options.utm_term = this.utms.term || 'none';
}
const params = new URLSearchParams(options); const params = new URLSearchParams(options);
location.assign( location.assign(
`${this.authConfig.authorization_endpoint}?${params.toString()}` `${this.authConfig.authorization_endpoint}?${params.toString()}`

View File

@ -104,10 +104,16 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
entrypoint: ep.entrypoint, entrypoint: ep.entrypoint,
file_count: ep.file_count, file_count: ep.file_count,
password_protected: ep.password_protected, password_protected: ep.password_protected,
referrer: ep.referrer,
size: ep.size, size: ep.size,
time_limit: ep.time_limit, time_limit: ep.time_limit,
trigger: ep.trigger, trigger: ep.trigger,
ttl: ep.ttl ttl: ep.ttl,
utm_campaign: ep.utm_campaign,
utm_content: ep.utm_content,
utm_medium: ep.utm_medium,
utm_source: ep.utm_source,
utm_term: ep.utm_term
}; };
const user_properties = { const user_properties = {
active_count: up.active_count, active_count: up.active_count,