@@ -1140,72 +1140,109 @@ export class AppComponent implements AfterViewInit {
11401140
11411141 public async initialDataTrackings ( ) {
11421142 const settings = this . uiSettingsStorage . getSettings ( ) ;
1143+ const impressionsToTrack : Array < {
1144+ contentName : string ;
1145+ contentPiece : string ;
1146+ contentTarget ?: string ;
1147+ } > = [ ] ;
11431148 if (
11441149 settings . matomo_analytics === true &&
11451150 settings . matomo_initial_data_tracked === false
11461151 ) {
11471152 try {
11481153 await this . uiAlert . showLoadingSpinner ( ) ;
1154+
11491155 const beans : Array < Bean > = this . uiBeanStorage . getAllEntries ( ) ;
1150- for ( let bean of beans ) {
1156+ const mills : Array < Mill > = this . uiMillStorage . getAllEntries ( ) ;
1157+ const preparations : Array < Preparation > =
1158+ this . uiPreparationStorage . getAllEntries ( ) ;
1159+ const waters : Array < Water > = this . uiWaterStorage . getAllEntries ( ) ;
1160+ const brewsCount = this . uiBrewStorage . getAllEntries ( ) . length ;
1161+ const beansCountFromStorage = this . uiBeanStorage . getAllEntries ( ) . length ;
1162+
1163+ for ( const bean of beans ) {
11511164 if ( bean . roaster ) {
1152- this . uiAnalytics . trackContentImpression (
1153- TrackContentImpression . STATISTICS_ROASTER_NAME ,
1154- bean . roaster ,
1155- ) ;
1156- this . uiAnalytics . trackContentImpression (
1157- TrackContentImpression . STATISTICS_BEAN_ROASTER_NAME ,
1158- bean . roaster + ' | ' + bean . name ,
1159- ) ;
1165+ impressionsToTrack . push ( {
1166+ contentName : TrackContentImpression . STATISTICS_ROASTER_NAME ,
1167+ contentPiece : bean . roaster ,
1168+ } ) ;
1169+ impressionsToTrack . push ( {
1170+ contentName : TrackContentImpression . STATISTICS_BEAN_ROASTER_NAME ,
1171+ contentPiece : ` ${ bean . roaster } | ${ bean . name } ` ,
1172+ } ) ;
11601173 } else {
1161- this . uiAnalytics . trackContentImpression (
1162- TrackContentImpression . STATISTICS_BEAN_ROASTER_NAME ,
1163- ' | ' + bean . name ,
1164- ) ;
1174+ impressionsToTrack . push ( {
1175+ contentName : TrackContentImpression . STATISTICS_BEAN_ROASTER_NAME ,
1176+ contentPiece : ` - | ${ bean . name } ` ,
1177+ } ) ;
11651178 }
11661179 }
1167- const mills : Array < Mill > = this . uiMillStorage . getAllEntries ( ) ;
11681180
1169- for ( let mill of mills ) {
1170- this . uiAnalytics . trackContentImpression (
1171- TrackContentImpression . STATISTICS_GRINDER_NAME ,
1172- mill . name ,
1173- ) ;
1181+ for ( const mill of mills ) {
1182+ impressionsToTrack . push ( {
1183+ contentName : TrackContentImpression . STATISTICS_GRINDER_NAME ,
1184+ contentPiece : mill . name ,
1185+ } ) ;
11741186 }
11751187
1176- const preparations : Array < Preparation > =
1177- this . uiPreparationStorage . getAllEntries ( ) ;
1178- for ( let preparation of preparations ) {
1179- this . uiAnalytics . trackContentImpression (
1180- TrackContentImpression . STATISTICS_PREPARATION_NAME ,
1181- preparation . name ,
1182- ) ;
1188+ for ( const preparation of preparations ) {
1189+ impressionsToTrack . push ( {
1190+ contentName : TrackContentImpression . STATISTICS_PREPARATION_NAME ,
1191+ contentPiece : preparation . name ,
1192+ } ) ;
11831193 }
11841194
1185- const waters : Array < Water > = this . uiWaterStorage . getAllEntries ( ) ;
1186- for ( let water of waters ) {
1187- this . uiAnalytics . trackContentImpression (
1188- TrackContentImpression . STATISTICS_WATER_NAME ,
1189- water . name ,
1190- ) ;
1195+ for ( const water of waters ) {
1196+ impressionsToTrack . push ( {
1197+ contentName : TrackContentImpression . STATISTICS_WATER_NAME ,
1198+ contentPiece : water . name ,
1199+ } ) ;
11911200 }
11921201
1193- settings . matomo_initial_data_tracked = true ;
1194- await this . uiSettingsStorage . update ( settings ) ;
1195- } catch ( ex ) { }
1202+ impressionsToTrack . push ( {
1203+ contentName : TrackContentImpression . STATISTICS_BREWS_COUNT ,
1204+ contentPiece : brewsCount . toString ( ) ,
1205+ } ) ;
1206+ impressionsToTrack . push ( {
1207+ contentName : TrackContentImpression . STATISTICS_BEANS_COUNT ,
1208+ contentPiece : beansCountFromStorage . toString ( ) ,
1209+ } ) ;
11961210
1197- await this . uiAlert . hideLoadingSpinner ( ) ;
1211+ if ( impressionsToTrack . length > 0 ) {
1212+ const didTrack =
1213+ await this . uiAnalytics . trackBulkContentImpressions (
1214+ impressionsToTrack ,
1215+ ) ;
1216+ if ( didTrack ) {
1217+ const currentSettings = this . uiSettingsStorage . getSettings ( ) ;
1218+ currentSettings . matomo_initial_data_tracked = true ;
1219+ await this . uiSettingsStorage . update ( currentSettings ) ;
1220+ }
1221+ } else {
1222+ // If there's nothing to track, still mark as tracked
1223+ const currentSettings = this . uiSettingsStorage . getSettings ( ) ;
1224+ currentSettings . matomo_initial_data_tracked = true ;
1225+ await this . uiSettingsStorage . update ( currentSettings ) ;
1226+ }
1227+ } catch ( ex ) {
1228+ this . uiLog . error ( 'Error during initial bulk data trackings: ' , ex ) ;
1229+ } finally {
1230+ await this . uiAlert . hideLoadingSpinner ( ) ;
1231+ }
1232+ } else if ( settings . matomo_analytics === true ) {
1233+ setTimeout ( ( ) => {
1234+ const brewsCount = this . uiBrewStorage . getAllEntries ( ) . length ;
1235+ const beansCountFromStorage = this . uiBeanStorage . getAllEntries ( ) . length ;
1236+ impressionsToTrack . push ( {
1237+ contentName : TrackContentImpression . STATISTICS_BREWS_COUNT ,
1238+ contentPiece : brewsCount . toString ( ) ,
1239+ } ) ;
1240+ impressionsToTrack . push ( {
1241+ contentName : TrackContentImpression . STATISTICS_BEANS_COUNT ,
1242+ contentPiece : beansCountFromStorage . toString ( ) ,
1243+ } ) ;
1244+ this . uiAnalytics . trackBulkContentImpressions ( impressionsToTrack ) ;
1245+ } , 5000 ) ;
11981246 }
1199-
1200- const brewsCount = this . uiBrewStorage . getAllEntries ( ) . length ;
1201- const beansCount = this . uiBeanStorage . getAllEntries ( ) . length ;
1202- this . uiAnalytics . trackContentImpression (
1203- TrackContentImpression . STATISTICS_BREWS_COUNT ,
1204- brewsCount . toString ( ) ,
1205- ) ;
1206- this . uiAnalytics . trackContentImpression (
1207- TrackContentImpression . STATISTICS_BEANS_COUNT ,
1208- beansCount . toString ( ) ,
1209- ) ;
12101247 }
12111248}
0 commit comments