-
-
Notifications
You must be signed in to change notification settings - Fork 196
Improve analytics #3088
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
Improve analytics #3088
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Submodule common
updated
15 files
+2 −0 | appbuilder/proton-static-config.ts | |
+2 −11 | commands/analytics.ts | |
+6 −0 | constants.ts | |
+39 −5 | declarations.d.ts | |
+1 −1 | definitions/config.d.ts | |
+35 −0 | definitions/eqatec-analytics.d.ts | |
+102 −0 | definitions/google-analytics.d.ts | |
+4 −0 | os-info.ts | |
+154 −117 | services/analytics-service-base.ts | |
+19 −0 | services/analytics-status.ts | |
+35 −0 | services/analytics-type.ts | |
+11 −1 | services/commands-service.ts | |
+10 −0 | services/google-analytics-data-type.ts | |
+2 −2 | static-config-base.ts | |
+43 −40 | test/unit-tests/analytics-service.ts |
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,60 @@ | ||
import * as fs from "fs"; | ||
import { AnalyticsBroker } from "./analytics-broker"; | ||
|
||
const pathToBootstrap = process.argv[2]; | ||
if (!pathToBootstrap || !fs.existsSync(pathToBootstrap)) { | ||
throw new Error("Invalid path to bootstrap."); | ||
} | ||
|
||
// After requiring the bootstrap we can use $injector | ||
require(pathToBootstrap); | ||
|
||
const analyticsBroker = $injector.resolve<IAnalyticsBroker>(AnalyticsBroker, { pathToBootstrap }); | ||
let trackingQueue: Promise<void> = Promise.resolve(); | ||
|
||
let sentFinishMsg = false; | ||
let receivedFinishMsg = false; | ||
|
||
const sendDataForTracking = async (data: ITrackingInformation) => { | ||
trackingQueue = trackingQueue.then(() => analyticsBroker.sendDataForTracking(data)); | ||
await trackingQueue; | ||
}; | ||
|
||
const finishTracking = async (data?: ITrackingInformation) => { | ||
if (!sentFinishMsg) { | ||
sentFinishMsg = true; | ||
|
||
data = data || { type: TrackingTypes.Finish }; | ||
const action = async () => { | ||
await sendDataForTracking(data); | ||
process.disconnect(); | ||
}; | ||
|
||
if (receivedFinishMsg) { | ||
await action(); | ||
} else { | ||
// In case we've got here without receiving "finish" message from parent (receivedFinishMsg is false) | ||
// there might be various reasons, but most probably the parent is dead. | ||
// However, there's no guarantee that we've received all messages. So wait some time before sending finish message to children. | ||
setTimeout(async () => { | ||
await action(); | ||
}, 1000); | ||
} | ||
} | ||
}; | ||
|
||
process.on("message", async (data: ITrackingInformation) => { | ||
if (data.type === TrackingTypes.Finish) { | ||
receivedFinishMsg = true; | ||
await finishTracking(data); | ||
return; | ||
} | ||
|
||
await sendDataForTracking(data); | ||
}); | ||
|
||
process.on("disconnect", async () => { | ||
await finishTracking(); | ||
}); | ||
|
||
process.send(AnalyticsMessages.BrokerReadyToReceive); |
This file contains hidden or 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 { cache } from "../../common/decorators"; | ||
|
||
export class AnalyticsBroker implements IAnalyticsBroker { | ||
|
||
@cache() | ||
private async getEqatecAnalyticsProvider(): Promise<IAnalyticsProvider> { | ||
return this.$injector.resolve("eqatecAnalyticsProvider"); | ||
} | ||
|
||
@cache() | ||
private async getGoogleAnalyticsProvider(): Promise<IGoogleAnalyticsProvider> { | ||
const clientId = await this.$analyticsSettingsService.getClientId(); | ||
return this.$injector.resolve("googleAnalyticsProvider", { clientId }); | ||
} | ||
|
||
constructor(private $analyticsSettingsService: IAnalyticsSettingsService, | ||
private $injector: IInjector) { } | ||
|
||
public async sendDataForTracking(trackInfo: ITrackingInformation): Promise<void> { | ||
const eqatecProvider = await this.getEqatecAnalyticsProvider(); | ||
const googleProvider = await this.getGoogleAnalyticsProvider(); | ||
|
||
switch (trackInfo.type) { | ||
case TrackingTypes.Exception: | ||
await eqatecProvider.trackError(<IExceptionsTrackingInformation>trackInfo); | ||
break; | ||
case TrackingTypes.Feature: | ||
await eqatecProvider.trackInformation(<IFeatureTrackingInformation>trackInfo); | ||
break; | ||
case TrackingTypes.AcceptTrackFeatureUsage: | ||
await eqatecProvider.acceptFeatureUsageTracking(<IAcceptUsageReportingInformation>trackInfo); | ||
break; | ||
case TrackingTypes.GoogleAnalyticsData: | ||
await googleProvider.trackHit(<IGoogleAnalyticsTrackingInformation>trackInfo); | ||
break; | ||
case TrackingTypes.Finish: | ||
await eqatecProvider.finishTracking(); | ||
break; | ||
default: | ||
throw new Error(`Invalid tracking type: ${trackInfo.type}`); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains hidden or 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,14 @@ | ||
/** | ||
* Defines messages used in communication between CLI's process and analytics subprocesses. | ||
*/ | ||
const enum AnalyticsMessages { | ||
/** | ||
* Analytics Broker is initialized and is ready to receive information for tracking. | ||
*/ | ||
BrokerReadyToReceive = "BrokerReadyToReceive", | ||
|
||
/** | ||
* Eqatec Analytics process is initialized and is ready to receive information for tracking. | ||
*/ | ||
EqatecAnalyticsReadyToReceive = "EqatecAnalyticsReadyToReceive" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can shorten the syntax here with
you don't need the
this
context and there's no one actuallyawait
-ing this promise