@@ -22,11 +22,14 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
2222
2323 await this . $analyticsService . track ( "Template used for project creation" , templateName ) ;
2424
25- await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
26- action : constants . TrackActionNames . CreateProject ,
27- isForDevice : null ,
28- additionalData : this . getTemplateNameToBeTracked ( templateName , realTemplatePath )
29- } ) ;
25+ const templateNameToBeTracked = this . getTemplateNameToBeTracked ( templateName , realTemplatePath ) ;
26+ if ( templateNameToBeTracked ) {
27+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
28+ action : constants . TrackActionNames . CreateProject ,
29+ isForDevice : null ,
30+ additionalData : templateNameToBeTracked
31+ } ) ;
32+ }
3033
3134 // this removes dependencies from templates so they are not copied to app folder
3235 this . $fs . deleteDirectory ( path . join ( realTemplatePath , constants . NODE_MODULES_FOLDER_NAME ) ) ;
@@ -48,19 +51,23 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
4851 }
4952
5053 private getTemplateNameToBeTracked ( templateName : string , realTemplatePath : string ) : string {
51- if ( this . $fs . exists ( templateName ) ) {
52- // local template is used
53- const pathToPackageJson = path . join ( realTemplatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
54- let templateNameToTrack = path . basename ( templateName ) ;
55- if ( this . $fs . exists ( pathToPackageJson ) ) {
56- const templatePackageJsonContent = this . $fs . readJson ( pathToPackageJson ) ;
57- templateNameToTrack = templatePackageJsonContent . name ;
54+ try {
55+ if ( this . $fs . exists ( templateName ) ) {
56+ // local template is used
57+ const pathToPackageJson = path . join ( realTemplatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
58+ let templateNameToTrack = path . basename ( templateName ) ;
59+ if ( this . $fs . exists ( pathToPackageJson ) ) {
60+ const templatePackageJsonContent = this . $fs . readJson ( pathToPackageJson ) ;
61+ templateNameToTrack = templatePackageJsonContent . name ;
62+ }
63+
64+ return `${ constants . ANALYTICS_LOCAL_TEMPLATE_PREFIX } ${ templateNameToTrack } ` ;
5865 }
5966
60- return `${ constants . ANALYTICS_LOCAL_TEMPLATE_PREFIX } ${ templateNameToTrack } ` ;
67+ return templateName ;
68+ } catch ( err ) {
69+ this . $logger . trace ( `Unable to get template name to be tracked, error is: ${ err } ` ) ;
6170 }
62-
63- return templateName ;
6471 }
6572}
6673$injector . register ( "projectTemplatesService" , ProjectTemplatesService ) ;
0 commit comments