-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into chat-app-4
- Loading branch information
Showing
11 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const CONFIG = { | ||
mixpanelToken: 'fad3409b4b79d03a837adc7db17f0e97', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as mixpanel from 'mixpanel'; | ||
import * as vscode from 'vscode'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { CONFIG } from '../config'; | ||
import * as os from 'os'; | ||
|
||
class MixpanelHelper { | ||
private static instance: MixpanelHelper; | ||
private mixpanelInstance: mixpanel.Mixpanel; | ||
private userId: string; | ||
|
||
private constructor(token: string, config?: mixpanel.InitConfig) { | ||
const defaultConfig = { | ||
geolocate: true | ||
}; | ||
|
||
// If there's any user-provided config, it will overwrite the defaults | ||
const finalConfig = { ...defaultConfig, ...config }; | ||
|
||
this.mixpanelInstance = mixpanel.init(token, finalConfig); | ||
|
||
// Retrieve or generate the userId | ||
this.userId = this.getUserId(); | ||
} | ||
|
||
static getInstance(config?: mixpanel.InitConfig): MixpanelHelper { | ||
if (!MixpanelHelper.instance) { | ||
MixpanelHelper.instance = new MixpanelHelper(CONFIG.mixpanelToken, config); | ||
} | ||
return MixpanelHelper.instance; | ||
} | ||
|
||
private getUserId(): string { | ||
const userId = vscode.workspace.getConfiguration().get<string>('NeatworkAi.neatcoder.userId'); | ||
if (userId) { | ||
return userId; | ||
} | ||
|
||
const newUserId = uuidv4(); | ||
vscode.workspace.getConfiguration().update('NeatworkAi.neatcoder.userId', newUserId, vscode.ConfigurationTarget.Global); | ||
return newUserId; | ||
} | ||
|
||
private getExtensionVersion(): string { | ||
const extension = vscode.extensions.getExtension('NeatworkAi.neatcoder'); | ||
return extension?.packageJSON.version || 'unknown'; | ||
} | ||
|
||
trackEvent(eventName: string, properties: mixpanel.PropertyDict = {}): void { | ||
properties.distinct_id = this.userId; | ||
properties.$os = os.type(); | ||
properties.extensionVersion = this.getExtensionVersion(); | ||
properties.moduleName = 'VSCodeExtension'; | ||
|
||
this.mixpanelInstance.track(eventName, properties, (err) => { | ||
if (err) { | ||
console.error('Error sending event to Mixpanel:', err); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default MixpanelHelper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const CONFIG = { | ||
mixpanelToken: 'fad3409b4b79d03a837adc7db17f0e97', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import mixpanel, { Dict } from 'mixpanel-browser'; | ||
import { CONFIG } from './config'; | ||
|
||
class MixpanelWebviewHelper { | ||
private static instance: MixpanelWebviewHelper; | ||
private userId: string | undefined; | ||
|
||
private constructor() { | ||
mixpanel.init(CONFIG.mixpanelToken); | ||
this.initializeUserId(); | ||
} | ||
|
||
private async initializeUserId() { | ||
this.userId = await this.getUserIdFromExtension(); | ||
mixpanel.identify(this.userId); | ||
} | ||
|
||
static getInstance(): MixpanelWebviewHelper { | ||
if (!MixpanelWebviewHelper.instance) { | ||
MixpanelWebviewHelper.instance = new MixpanelWebviewHelper(); | ||
} | ||
return MixpanelWebviewHelper.instance; | ||
} | ||
|
||
private getUserIdFromExtension(): Promise<string> { | ||
return new Promise((resolve) => { | ||
const vscode = acquireVsCodeApi(); | ||
vscode.postMessage({ command: 'getUserId' }); | ||
|
||
window.addEventListener('message', event => { | ||
const message = event.data; | ||
if (message.command === 'userId') { | ||
resolve(message.userId); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
trackEvent(eventName: string, properties: Dict = {}): void { | ||
properties.moduleName = 'Webview'; | ||
mixpanel.track(eventName, properties); | ||
} | ||
} | ||
|
||
export default MixpanelWebviewHelper; |