2626
2727import com .amazonaws .logging .Log ;
2828import com .amazonaws .logging .LogFactory ;
29+ import software .aws .solution .clickstream .client .AnalyticsClient ;
2930import software .aws .solution .clickstream .client .AnalyticsEvent ;
3031import software .aws .solution .clickstream .client .AutoRecordEventClient ;
3132import software .aws .solution .clickstream .client .ClickstreamManager ;
33+ import software .aws .solution .clickstream .client .Event ;
3234import software .aws .solution .clickstream .client .ScreenRefererTool ;
3335import software .aws .solution .clickstream .client .SessionClient ;
36+ import software .aws .solution .clickstream .client .util .StringUtil ;
3437
3538/**
3639 * Tracks when the host application enters or leaves foreground.
@@ -41,6 +44,7 @@ final class ActivityLifecycleManager implements Application.ActivityLifecycleCal
4144 private static boolean isFromForeground ;
4245 private final SessionClient sessionClient ;
4346 private final AutoRecordEventClient autoRecordEventClient ;
47+ private final AnalyticsClient analyticsClient ;
4448
4549 /**
4650 * Constructor. Registers to receive activity lifecycle events.
@@ -49,6 +53,7 @@ final class ActivityLifecycleManager implements Application.ActivityLifecycleCal
4953 */
5054 ActivityLifecycleManager (final ClickstreamManager clickstreamManager ) {
5155 this .sessionClient = clickstreamManager .getSessionClient ();
56+ this .analyticsClient = clickstreamManager .getAnalyticsClient ();
5257 this .autoRecordEventClient = clickstreamManager .getAutoRecordEventClient ();
5358 }
5459
@@ -145,11 +150,27 @@ public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Life
145150 LOG .debug ("Application entered the foreground." );
146151 isFromForeground = true ;
147152 autoRecordEventClient .handleAppStart ();
153+ autoRecordEventClient .updateStartEngageTimestamp ();
148154 boolean isNewSession = sessionClient .initialSession ();
149155 if (isNewSession ) {
150156 autoRecordEventClient .setIsEntrances ();
157+ recordScreenViewAfterSessionStart ();
151158 }
152- autoRecordEventClient .updateStartEngageTimestamp ();
159+ }
160+ }
161+
162+ private void recordScreenViewAfterSessionStart () {
163+ if (!StringUtil .isNullOrEmpty (ScreenRefererTool .getCurrentScreenName ())) {
164+ String screenName = ScreenRefererTool .getCurrentScreenName ();
165+ String screenId = ScreenRefererTool .getCurrentScreenId ();
166+ String screenUniqueId = ScreenRefererTool .getCurrentScreenUniqueId ();
167+ ScreenRefererTool .clear ();
168+ AnalyticsEvent clickstreamEvent =
169+ analyticsClient .createEvent (Event .PresetEvent .SCREEN_VIEW );
170+ clickstreamEvent .addAttribute (Event .ReservedAttribute .SCREEN_NAME , screenName );
171+ clickstreamEvent .addAttribute (Event .ReservedAttribute .SCREEN_ID , screenId );
172+ clickstreamEvent .addAttribute (Event .ReservedAttribute .SCREEN_UNIQUE_ID , screenUniqueId );
173+ autoRecordEventClient .recordViewScreenManually (clickstreamEvent );
153174 }
154175 }
155176}
0 commit comments