Skip to content

Commit 1279479

Browse files
authored
Implement events (codesandbox#2336)
* Implement events * Add workbench event whitelist * Add move pane event
1 parent 8a410f1 commit 1279479

File tree

12 files changed

+143
-14
lines changed

12 files changed

+143
-14
lines changed

packages/app/src/app/components/Preview/DevTools/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import store from 'store/dist/store.modern';
55

66
import { TemplateType } from '@codesandbox/common/lib/templates';
77
import { ViewConfig } from '@codesandbox/common/lib/templates/template';
8+
import track from '@codesandbox/common/lib/utils/analytics';
89

910
import console from './Console';
1011
import Tabs, { ITabPosition } from './Tabs';
@@ -112,7 +113,7 @@ type State = {
112113
currentTabIndex: number;
113114
};
114115

115-
export default class DevTools extends React.PureComponent<Props, State> {
116+
export class DevTools extends React.PureComponent<Props, State> {
116117
constructor(props: Props) {
117118
super(props);
118119

@@ -383,6 +384,11 @@ export default class DevTools extends React.PureComponent<Props, State> {
383384
if (this.state.hidden && !this.props.primary) {
384385
this.openDevTools();
385386
}
387+
const pane = this.props.viewConfig.views[index];
388+
if (pane) {
389+
track('DevTools - Open Pane', { pane: pane.id });
390+
}
391+
386392
this.props.setPane({
387393
devToolIndex: this.props.devToolIndex,
388394
tabPosition: index,
@@ -473,6 +479,10 @@ export default class DevTools extends React.PureComponent<Props, State> {
473479
moveTab={
474480
this.props.moveTab
475481
? (prevPos, nextPos) => {
482+
track('DevTools - Move Pane', {
483+
pane: this.props.viewConfig.views[prevPos.tabPosition]
484+
.id,
485+
});
476486
this.props.moveTab(prevPos, nextPos);
477487
}
478488
: undefined

packages/app/src/app/pages/Dashboard/Content/CreateNewSandbox/NewSandboxModal/Imports/GitHubImport.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
gitHubRepoPattern,
66
} from '@codesandbox/common/lib/utils/url-generator';
77
import { Button } from '@codesandbox/common/lib/components/Button';
8+
import track from '@codesandbox/common/lib/utils/analytics';
89

910
import {
1011
ImportHeader,
@@ -102,7 +103,14 @@ export const GitHubImport = () => {
102103
>
103104
Copy Link
104105
</Button>
105-
<Button disabled={!transformedUrl} to={gitHubToSandboxUrl(url)} small>
106+
<Button
107+
onClick={() => {
108+
track('GitHub Import Wizard - Open Sandbox Clicked');
109+
}}
110+
disabled={!transformedUrl}
111+
to={gitHubToSandboxUrl(url)}
112+
small
113+
>
106114
Open Sandbox
107115
</Button>
108116
</Buttons>

packages/app/src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import SplitPane from 'react-split-pane';
1212

1313
import CodeEditor from 'app/components/CodeEditor';
1414
import type { Editor, Settings } from 'app/components/CodeEditor/types';
15-
import DevTools from 'app/components/Preview/DevTools';
15+
import { DevTools } from 'app/components/Preview/DevTools';
1616

1717
import Preview from './Preview';
1818
import preventGestureScroll, { removeListener } from './prevent-gesture-scroll';

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Deployment/Netlify/DeployButton/DeployButton.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import track from '@codesandbox/common/lib/utils/analytics';
23
import { inject, hooksObserver } from 'app/componentConnectors';
34
import { DeploymentIntegration } from 'app/components/DeploymentIntegration';
45
import { NetlifyLogo } from 'app/components/NetlifyLogo';
@@ -27,7 +28,10 @@ export const DeployButton = inject('store', 'signals')(
2728
<DeploymentIntegration
2829
beta
2930
bgColor="#FFFFFF"
30-
onDeploy={deployWithNetlify}
31+
onDeploy={() => {
32+
track('Deploy Clicked', { provider: 'netlify' });
33+
deployWithNetlify({});
34+
}}
3135
Icon={NetlifyLogo}
3236
light
3337
loading={deploying || building}

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/GitHub/CreateRepo/CreateRepo.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button } from '@codesandbox/common/lib/components/Button';
22
import Input from '@codesandbox/common/lib/components/Input';
33
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
4+
import track from '@codesandbox/common/lib/utils/analytics';
45
import { inject, hooksObserver } from 'app/componentConnectors';
56
import React from 'react';
67

@@ -31,7 +32,10 @@ export const CreateRepo = inject('store', 'signals')(
3132
const updateRepoTitle = ({
3233
target: { value: title },
3334
}: React.ChangeEvent<HTMLInputElement>) => repoTitleChanged({ title });
34-
const createRepo = () => createRepoClicked();
35+
const createRepo = () => {
36+
track('Export to GitHub Clicked');
37+
createRepoClicked();
38+
};
3539

3640
return (
3741
<div style={style}>

packages/app/src/app/pages/common/Modals/DeploymentModal/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Margin from '@codesandbox/common/lib/components/spacing/Margin';
55
import { inject, observer } from 'app/componentConnectors';
66
import ZeitIntegration from 'app/pages/common/ZeitIntegration';
77
import { IntegrationModal } from 'app/components/IntegrationModal';
8+
import track from '@codesandbox/common/lib/utils/analytics';
89
import {
910
ButtonContainer,
1011
DeployAnimationContainer,
@@ -84,7 +85,10 @@ function DeploymentModal({ store, signals }) {
8485
) : (
8586
<ButtonContainer deploying={store.deployment.deploying}>
8687
<Button
87-
onClick={() => signals.deployment.deployClicked()}
88+
onClick={() => {
89+
track('Deploy Clicked', { provider: 'zeit' });
90+
signals.deployment.deployClicked();
91+
}}
8892
disabled={!zeitSignedIn || store.deployment.deploying}
8993
>
9094
Deploy Now

packages/app/src/app/store/providers/Api.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ function showNotification(controller, errorMessage: string) {
6969
} else if (errorMessage.startsWith('You reached the maximum of')) {
7070
track('Non-Patron Sandbox Limit Reached', { errorMessage });
7171

72+
notificationState.addNotification({
73+
title: errorMessage,
74+
status: NotificationStatus.ERROR,
75+
actions: {
76+
primary: [
77+
{
78+
label: 'Open Patron Page',
79+
run: () => {
80+
window.open(patronUrl(), '_blank');
81+
},
82+
},
83+
],
84+
},
85+
});
86+
} else if (
87+
errorMessage.startsWith(
88+
'You reached the limit of server sandboxes, you can create more server sandboxes as a patron.'
89+
)
90+
) {
91+
track('Non-Patron Server Sandbox Limit Reached', { errorMessage });
92+
7293
notificationState.addNotification({
7394
title: errorMessage,
7495
status: NotificationStatus.ERROR,
@@ -84,6 +105,14 @@ function showNotification(controller, errorMessage: string) {
84105
},
85106
});
86107
} else {
108+
if (
109+
errorMessage.startsWith(
110+
'You reached the limit of server sandboxes, we will increase the limit in the future. Please contact [email protected] for more server sandboxes.'
111+
)
112+
) {
113+
track('Patron Server Sandbox Limit Reached', { errorMessage });
114+
}
115+
87116
controller.runSignal(
88117
'notificationAdded',
89118
addNotification(errorMessage, 'error')

packages/app/src/embed/components/Content/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
StyledCloseIcon,
2727
} from 'app/pages/Sandbox/Editor/Content/Tabs/Tab/elements';
2828

29-
import DevTools, {
29+
import {
30+
DevTools,
3031
IViewType,
3132
DevToolProps,
3233
} from 'app/components/Preview/DevTools';

packages/app/src/embed/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import theme from '@codesandbox/common/lib/theme';
99
import '@codesandbox/common/lib/global.css';
1010

1111
import codesandbox from '@codesandbox/common/lib/themes/codesandbox.json';
12+
import track from '@codesandbox/common/lib/utils/analytics';
1213

1314
import App from './components/App';
1415

16+
document.addEventListener('click', () => {
17+
track('Embed Interaction');
18+
});
19+
1520
requirePolyfills().then(() => {
1621
function renderApp(Component) {
1722
render(

packages/common/src/components/Navigation/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Logo from '../Logo';
55
import MaxWidth from '../flex/MaxWidth';
66

77
import media from '../../utils/media';
8+
import track from '../../utils/analytics';
89

910
const Container = styled.div`
1011
display: flex;
@@ -167,7 +168,15 @@ export default class Navigation extends React.PureComponent {
167168
</Item>
168169
)}
169170

170-
<Item hidePhone href="/s" rel="noopener noreferrer" button={!user}>
171+
<Item
172+
onClick={() => {
173+
track('Navigation - Create Sandbox Clicked');
174+
}}
175+
hidePhone
176+
href="/s"
177+
rel="noopener noreferrer"
178+
button={!user}
179+
>
171180
Create Sandbox
172181
</Item>
173182

0 commit comments

Comments
 (0)