To interact with Google Analytics, you can leverage the class GoogleAnalytics which is available in the JavaScript context.
It provides methods to register and interact with Google Analytics 4.
Here is a sample code about class usage:
const gaTracker = GoogleAnalyticsTracker.create({"tagManagerId": "<GOOGLE_TAG_MANAGER_ID>"});
// event logging a widget has been viewed
gaTracker.logEvent("abc-widget viewed");
// set properties you can use to segment users
gaTracker.setUserPropertiesReader(function(user) {
return {"persona": (user.organizationId || user.partnerId) ? "SERVICE" : "CUSTOMER"};
});