Skip to content

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

Merged
merged 1 commit into from
Mar 1, 2018

Conversation

Fatme
Copy link
Contributor

@Fatme Fatme commented Feb 27, 2018

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
		}
	}
}

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.

return result;
}

return await this.getPlaygroundInfoFromUserSettingsFile();
Copy link
Contributor

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.

Copy link
Contributor

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.

return projectFileContent && projectFileContent.nativescript && projectFileContent.nativescript.playground && projectFileContent.nativescript.playground.id;
}

private async getPlaygroundInfoFromUserSettingsFile() {
Copy link
Contributor

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,
Copy link
Contributor

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


// 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) {
Copy link
Contributor

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


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>{};
Copy link
Contributor

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>{}

userSettingsService.saveSettings = async (settings: any) => { userSettings = settings; };

const fs = testInjector.resolve<IFileSystem>("fs");
fs.readJson = () => data && data.nativescriptKey ? data.nativescriptKey : {};
Copy link
Contributor

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

}

describe("PlaygroundService", () => {
let testInjector: IInjector = null;
Copy link
Contributor

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

const result = await playgroundService.getPlaygroundInfo();
assert.equal(result, null);
});
it("should return null when projectDir has no nativescript key in package.json file", async () => {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fatme Fatme force-pushed the fatme/playground branch 2 times, most recently from 7150feb to 08ebd7b Compare February 28, 2018 08:11
@dtopuzov
Copy link
Contributor

run ci

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.
@@ -70,6 +71,12 @@ export class GoogleAnalyticsProvider implements IGoogleAnalyticsProvider {
[GoogleAnalyticsCustomDimensions.client]: AnalyticsClients.Unknown
};

const playgrounInfo = await this.$playgroundService.getPlaygroundInfo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playgrounInfo -> playgroundInfo

private getProjectData(projectDir: string): IProjectData {
try {
return this.$projectDataService.getProjectData(projectDir);
} catch (e) { // in case command is executed in non-project folder
Copy link
Contributor

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

fs.readJson = () => (data && data.nativescriptKey) || {};
}

describe.only("PlaygroundService", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this only

@rosen-vladimirov rosen-vladimirov merged commit dc345f4 into release Mar 1, 2018
@rosen-vladimirov rosen-vladimirov deleted the fatme/playground branch March 1, 2018 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants