mirror of
https://gitlab.com/timvisee/send.git
synced 2024-11-10 05:02:45 +01:00
utms for everybody
This commit is contained in:
parent
c8ea3a6138
commit
5e04f367c1
@ -106,6 +106,14 @@ export default function(state, emitter) {
|
||||
});
|
||||
|
||||
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);
|
||||
render();
|
||||
});
|
||||
|
@ -16,8 +16,15 @@ export default function initialize(state, emitter) {
|
||||
}
|
||||
emitter.on('DOMContentLoaded', () => {
|
||||
// experiment = storage.enrolled[0];
|
||||
const query = appState.query;
|
||||
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);
|
||||
|
34
app/user.js
34
app/user.js
@ -94,6 +94,29 @@ export default class User {
|
||||
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) {
|
||||
const state = arrayToB64(crypto.getRandomValues(new Uint8Array(16)));
|
||||
storage.set('oauthState', state);
|
||||
@ -111,6 +134,17 @@ export default class User {
|
||||
if (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);
|
||||
location.assign(
|
||||
`${this.authConfig.authorization_endpoint}?${params.toString()}`
|
||||
|
@ -104,10 +104,16 @@ function clientEvent(event, ua, language, session_id, deltaT, platform, ip) {
|
||||
entrypoint: ep.entrypoint,
|
||||
file_count: ep.file_count,
|
||||
password_protected: ep.password_protected,
|
||||
referrer: ep.referrer,
|
||||
size: ep.size,
|
||||
time_limit: ep.time_limit,
|
||||
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 = {
|
||||
active_count: up.active_count,
|
||||
|
Loading…
Reference in New Issue
Block a user