// // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // #ifndef ISEMANTICCONTEXT_HPP #define ISEMANTICCONTEXT_HPP #include "EventProperty.hpp" #include "CommonFields.h" #include "ctmacros.hpp" #include "Enums.hpp" #include #include namespace MAT_NS_BEGIN { /// class MATSDK_LIBABI ISemanticContext { public: virtual ~ISemanticContext() {}; /// /// Set the application environment context information of telemetry event. /// /// Environment from which this event originated DECLARE_COMMONFIELD(AppEnv, COMMONFIELDS_APP_ENV); /// /// Set the application identifier context information of telemetry event. /// /// Id that uniquely identifies the user-facing application from which this event originated DECLARE_COMMONFIELD(AppId, COMMONFIELDS_APP_ID); /// /// Set the application name context information of telemetry event. /// /// Application Name DECLARE_COMMONFIELD(AppName, COMMONFIELDS_APP_NAME); /// /// Set the application version context information of telemetry event. /// /// Version of the application, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(AppVersion, COMMONFIELDS_APP_VERSION); /// /// Set the application language context information of telemetry event. /// DECLARE_COMMONFIELD(AppLanguage, COMMONFIELDS_APP_LANGUAGE); /// /// Set the application's experiment IDs information of telemetry event. /// The experiment IDs information will be applied to all events unless it is overwritten by that set via SetEventExperimentIds /// /// list of IDs of experimentations into which the application is enlisted DECLARE_COMMONFIELD(AppExperimentIds, COMMONFIELDS_APP_EXPERIMENTIDS); /// /// Set the application version context information of telemetry event. /// Removes previously stored experiment ids set by SetAppExperimentIds. /// /// ETAG which is a hash of the set of experimentations into which the application is enlisted virtual void SetAppExperimentETag(std::string const& appExperimentETag) { SetCommonField(COMMONFIELDS_APP_EXPERIMENTETAG, appExperimentETag); ClearExperimentIds(); }; /// /// Set the application experimentation impression id information of telemetry event. /// /// List of expementation IDs which are app/platform specific DECLARE_COMMONFIELD(AppExperimentImpressionId, SESSION_IMPRESSION_ID); /// /// Set the experiment IDs information of the specified telemetry event. /// /// list of IDs of experimentations into which the application is enlisted virtual void SetEventExperimentIds(std::string const& /*eventName*/, std::string const& /*experimentIds*/) {}; /// /// Clear the experiment IDs information. /// virtual void ClearExperimentIds() {}; /// /// Set the device identifier context information of telemetry event. /// /// A unique device identifier, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(DeviceId, COMMONFIELDS_DEVICE_ID); /// /// Set the device manufacturer context information of telemetry event. /// /// The manufacturer of the device, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(DeviceMake, COMMONFIELDS_DEVICE_MAKE); /// /// Set the device model context information of telemetry event. /// /// The model of the device, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(DeviceModel, COMMONFIELDS_DEVICE_MODEL); /// /// Set the device class context information of telemetry event. /// /// Device class. DECLARE_COMMONFIELD(DeviceClass, COMMONFIELDS_DEVICE_CLASS); /// /// Set the device orgId context information of telemetry event. /// /// Device orgId DECLARE_COMMONFIELD(DeviceOrgId, COMMONFIELDS_DEVICE_ORGID); /// /// Set the network cost context information of telemetry event. /// /// The cost of using data traffic on the current network virtual void SetNetworkCost(NetworkCost networkCost) { char const* value; switch (networkCost) { case NetworkCost_Unknown: value = "Unknown"; break; case NetworkCost_Unmetered: value = "Unmetered"; break; case NetworkCost_Metered: value = "Metered"; break; case NetworkCost_OverDataLimit: value = "OverDataLimit"; break; default: assert(!"Unknown NetworkCost enum value"); value = ""; break; } SetCommonField(COMMONFIELDS_NETWORK_COST, value); } /// /// Set the network provider context information of telemetry event. /// /// The provider used to connect to the current network, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(NetworkProvider, COMMONFIELDS_NETWORK_PROVIDER); /// Set the network type context information of telemetry event. /// /// The type of the current network virtual void SetNetworkType(NetworkType networkType) { char const* value; switch (networkType) { case NetworkType_Unknown: value = "Unknown"; break; case NetworkType_Wired: value = "Wired"; break; case NetworkType_Wifi: value = "Wifi"; break; case NetworkType_WWAN: value = "WWAN"; break; default: assert(!"Unknown NetworkType enum value"); value = ""; break; } SetCommonField(COMMONFIELDS_NETWORK_TYPE, value); } /// /// Set the system name context information of telemetry event. /// /// The system anme, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(OsName, COMMONFIELDS_OS_NAME); /// /// Set the system version context information of telemetry event. /// /// The system version, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(OsVersion, COMMONFIELDS_OS_VERSION); /// /// Set the system build number context information of telemetry event. /// /// The system build, retrieved programmatically where possible and is app/platform specific DECLARE_COMMONFIELD(OsBuild, COMMONFIELDS_OS_BUILD); /// /// Set the userId context information of telemetry event. /// /// Identifier that uniquely identifies a user in the application-specific user namespace /// PIIKind of the userId. Default to PiiKind_Identity, set it to PiiKind_None to denote it as non-PII. virtual void SetUserId(std::string const& userId, PiiKind piiKind = PiiKind_Identity) { EventProperty prop(userId, piiKind); SetCommonField(COMMONFIELDS_USER_ID, prop); } /// /// Set the user MsaId context information of telemetry event. /// /// Msa id that identifies a user in the application-specific user namespace DECLARE_COMMONFIELD(UserMsaId, COMMONFIELDS_USER_MSAID); /// /// Set the user ANID context information of telemetry event. /// /// ANID that identifies a user in in the application-specific user namespace DECLARE_COMMONFIELD(UserANID, COMMONFIELDS_USER_ANID); /// /// Set the advertising Id context information of telemetry event. /// /// Advertising Id of a user to use in an application-specific user namespace DECLARE_COMMONFIELD(UserAdvertisingId, COMMONFIELDS_USER_ADVERTISINGID); /// /// Set the user language context information of telemetry event. /// /// user's language in IETF language tag format, as described in RFC 4646. DECLARE_COMMONFIELD(UserLanguage, COMMONFIELDS_USER_LANGUAGE); /// /// Set the user time zone context information of telemetry event. /// /// user's time zone relative to UTC, in ISO 8601 time zone format DECLARE_COMMONFIELD(UserTimeZone, COMMONFIELDS_USER_TIMEZONE); /// /// Set the Commercial Id context information of telemetry event. /// /// CommercialId of a machine DECLARE_COMMONFIELD(CommercialId, COMMONFIELDS_COMMERCIAL_ID); /// /// Sets the common Part A/B field. /// /// Field name /// Field value. virtual void SetCommonField(const std::string &, const EventProperty &) {}; /// /// Sets the custom Part C field. /// /// Field name /// Field value. virtual void SetCustomField(const std::string &, const EventProperty &) {}; /// /// Sets the ticket (device ticket, user id ticket, etc.) for secure token validation. /// /// Ticket type /// Ticket value. virtual void SetTicket(TicketType /*type*/, std::string const& /*ticketValue*/) {}; }; } MAT_NS_END #endif //ISEMANTICCONTEXT_H