+
Skip to content

Ask new users for an email, though this still works without it #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 31, 2022
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
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const GET_PICARD_CONTAINER_FUNCTION = `get_picard_container() {
}`;
export const GET_LICENSE_KEY_URL =
'https://getlocalci.com/pricing/?utm_medium=extension&utm_source=ui';
export const EMAIL_ENDPOINT =
'https://getlocalci.com/wp-json/gf-integration/v1/email';
export const HELP_URL = 'https://github.com/getlocalci/local-ci/discussions';
export const JOB_TREE_VIEW_ID = 'localCiJobs';
export const LICENSE_ITEM_ID = 43;
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import prepareConfig from './utils/prepareConfig';
import runJob from './utils/runJob';
import showLicenseInput from './utils/showLicenseInput';
import showLogFile from './utils/showLogFile';
import askForEmail from './utils/askForEmail';

const reporter = new TelemetryReporter(
EXTENSION_ID,
Expand All @@ -55,6 +56,7 @@ export function activate(context: vscode.ExtensionContext): void {
if (!context.globalState.get(TRIAL_STARTED_TIMESTAMP)) {
context.globalState.update(TRIAL_STARTED_TIMESTAMP, new Date().getTime());
reporter.sendTelemetryEvent('firstActivation');
askForEmail();

const getStartedText = 'Get started debugging faster';
vscode.window
Expand Down
47 changes: 47 additions & 0 deletions src/test/suite/utils/sendEnteredEmail.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as assert from 'assert';
import * as mocha from 'mocha';
import * as sinon from 'sinon';
import axios from 'axios';

import sendEnteredEmail from '../../../utils/sendEnteredEmail';
import { EMAIL_ENDPOINT } from '../../../constants';

mocha.afterEach(() => {
sinon.restore();
});

suite('sendEnteredEmail', () => {
test('only email', async () => {
const email = 'a@example.com';

const spy = sinon.spy();
sinon.stub(axios, 'post').value(spy);

await sendEnteredEmail(email);
assert(
spy.calledOnceWith(EMAIL_ENDPOINT, {
name: undefined,
email,
optedIn: undefined,
})
);
});

test('all fields', async () => {
const email = 'a@example.com';
const name = 'Jane';
const optedIn = true;

const spy = sinon.spy();
sinon.stub(axios, 'post').value(spy);

await sendEnteredEmail(email, name, optedIn);
assert(
spy.calledOnceWith(EMAIL_ENDPOINT, {
name,
email,
optedIn,
})
);
});
});
43 changes: 43 additions & 0 deletions src/utils/askForEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as vscode from 'vscode';
import sendEnteredEmail from './sendEnteredEmail';

export default function askForEmail(): void {
vscode.window
.showInputBox({
title: 'Email',
prompt:
'Could you please enter your email for your free preview of Local CI?',
})
.then((enteredEmail) => {
if (enteredEmail === undefined) {
return; // They pressed Escape or exited the input box.
}

vscode.window
.showInputBox({
title: 'Name',
prompt: `Thanks a lot! What's your first name?`,
})
.then((enteredName) => {
if (enteredName === undefined) {
sendEnteredEmail(enteredEmail); // They pressed Escape or exited the input box.
return;
}

const yesText = 'Yes';
vscode.window
.showQuickPick(['No', yesText], {
title: `Thanks so much! Can I send you occasional emails with CI/CD tips? You can unsubscribe any time. I'll never share your email.`,
})
.then(async (selection) => {
const optedIntoNewsletter = selection === yesText;

vscode.window.showInformationMessage(
'Thanks a lot, your free preview has started!',
{ detail: 'Local CI free preview' }
);
sendEnteredEmail(enteredEmail, enteredName, optedIntoNewsletter);
});
});
});
}
14 changes: 14 additions & 0 deletions src/utils/sendEnteredEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios';
import { EMAIL_ENDPOINT } from '../constants';

export default async function sendEnteredEmail(
email: string,
name?: string,
optedIn?: boolean
): Promise<void> {
await axios.post(EMAIL_ENDPOINT, {
name,
email,
optedIn,
});
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载