-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat(Analytics): Respect playground key from package.json file #3396
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
Conversation
lib/services/playground-service.ts
Outdated
return result; | ||
} | ||
|
||
return await this.getPlaygroundInfoFromUserSettingsFile(); |
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.
I believe this line should be outside of the if
statement as we want to return the settings from userSettingsFile even when the command is not executed in a project (i.e. when there's no projectData.
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.
also you do not need await
after return.
lib/services/playground-service.ts
Outdated
return projectFileContent && projectFileContent.nativescript && projectFileContent.nativescript.playground && projectFileContent.nativescript.playground.id; | ||
} | ||
|
||
private async getPlaygroundInfoFromUserSettingsFile() { |
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.
this method needs a return type
const defaultValues: IStringDictionary = { | ||
[GoogleAnalyticsCustomDimensions.cliVersion]: this.$staticConfig.version, | ||
[GoogleAnalyticsCustomDimensions.nodeVersion]: process.version, | ||
[GoogleAnalyticsCustomDimensions.clientID]: this.clientId, | ||
[GoogleAnalyticsCustomDimensions.projectType]: null, | ||
[GoogleAnalyticsCustomDimensions.sessionID]: sessionId, | ||
[GoogleAnalyticsCustomDimensions.client]: AnalyticsClients.Unknown | ||
[GoogleAnalyticsCustomDimensions.client]: AnalyticsClients.Unknown, |
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 do not need this change
lib/services/playground-service.ts
Outdated
|
||
// In case when usedTutorial=true is already saved in userSettings file, we shouldn't overwrite it | ||
const playgroundInfo = await this.getPlaygroundInfoFromUserSettingsFile(); | ||
if (playgroundInfo && playgroundInfo.usedTutorial === true) { |
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.
just if (playgroundInfo && playgroundInfo.usedTutorial)
is enough
test/services/playground-service.ts
Outdated
|
||
function mockPlaygroundService(testInjector: IInjector, data?: { projectData?: any, nativescriptKey?: any, userSettingsData?: any}) { | ||
const projectDataService = testInjector.resolve<IProjectDataService>("projectDataService"); | ||
projectDataService.getProjectData = () => (data && data.projectData) ? data.projectData : <IProjectData>{}; |
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 this:
data && data.projectData || <IProjectData>{}
test/services/playground-service.ts
Outdated
userSettingsService.saveSettings = async (settings: any) => { userSettings = settings; }; | ||
|
||
const fs = testInjector.resolve<IFileSystem>("fs"); | ||
fs.readJson = () => data && data.nativescriptKey ? data.nativescriptKey : {}; |
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.
same as above - this can be shortend
test/services/playground-service.ts
Outdated
} | ||
|
||
describe("PlaygroundService", () => { | ||
let testInjector: IInjector = null; |
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.
one space between let and testInjector should be enough
test/services/playground-service.ts
Outdated
const result = await playgroundService.getPlaygroundInfo(); | ||
assert.equal(result, null); | ||
}); | ||
it("should return null when projectDir has no nativescript key in package.json file", async () => { |
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.
In this case we would like to get the values from userSettings file.
@@ -898,6 +898,28 @@ getUserAgentString(identifier: string): string; | |||
const userAgentString = tns.analyticsSettingsService.getUserAgentString("tns/3.3.0"); | |||
``` | |||
|
|||
### getPlaygroundInfo | |||
The `getPlaygroundInfo` method allows retrieving information for projects that are exported from playground |
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.
Please note when this method returns null or undefined.
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.
7150feb
to
08ebd7b
Compare
run ci |
08ebd7b
to
8b8df2f
Compare
We need to track users that export their projects from playground and opens them in CLI or Sidekick. To support that we introduce playground key in nativescript key in package.json file. For example: ``` { "nativescript": { "playground": { "id": "some user quid", "usedTutorial": false // is not obligatory. In case it is present, can be true or false } } } ``` If case when package.json file contains playground key, {N} CLI reads playground data and saves them in userSettings file. If usedTutorial=true is already saved in userSettings file, {N} CLI does not overwrite it. After that {N} CLI deletes playground key from package.json file. In case when package.json file does not contain playground key, {N} CLI checks if playground key is already saved in userSettings file. It this is the case, {N} CLI reads playground data from userSettings file.
8b8df2f
to
76e29f8
Compare
@@ -70,6 +71,12 @@ export class GoogleAnalyticsProvider implements IGoogleAnalyticsProvider { | |||
[GoogleAnalyticsCustomDimensions.client]: AnalyticsClients.Unknown | |||
}; | |||
|
|||
const playgrounInfo = await this.$playgroundService.getPlaygroundInfo(); |
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.
playgrounInfo
-> playgroundInfo
lib/services/playground-service.ts
Outdated
private getProjectData(projectDir: string): IProjectData { | ||
try { | ||
return this.$projectDataService.getProjectData(projectDir); | ||
} catch (e) { // in case command is executed in non-project folder |
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.
can you move this comment on the next line
test/services/playground-service.ts
Outdated
fs.readJson = () => (data && data.nativescriptKey) || {}; | ||
} | ||
|
||
describe.only("PlaygroundService", () => { |
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.
please remove this only
We need to track users that export their projects from playground and opens them in CLI or Sidekick. To support that we introduce playground key in nativescript key in package.json file. For example:
In case when package.json file contains playground key, {N} CLI reads playground data and saves it in userSettings file. If usedTutorial=true is already saved in userSettings file, {N} CLI does not overwrite it. After that {N} CLI deletes playground key from package.json file.
In case when package.json file does not contain playground key, {N} CLI checks if playground key is already saved in userSettings file. If this is the case, {N} CLI reads playground data from userSettings file.