public AnalyticsSenderBuilder WithCommandLineArgs(IAnalyticsCommandLineArgs parsedArgs) { if (!string.IsNullOrEmpty(parsedArgs.ConfigPath)) { _config = AnalyticsConfig.FromFile(parsedArgs.ConfigPath); } if (!string.IsNullOrEmpty(parsedArgs.Endpoint)) { _endpoint = new Uri(parsedArgs.Endpoint); } if (!string.IsNullOrEmpty(parsedArgs.GcpKeyPath)) { _gcpKey = File.ReadAllText(parsedArgs.GcpKeyPath).Trim(); } if (!string.IsNullOrEmpty(parsedArgs.Environment)) { bool result = Enum.TryParse(parsedArgs.Environment, ignoreCase: true, result: out _environment); if (!result) { throw new ArgumentException($"Invalid environment {parsedArgs.Environment} given"); } } _allowUnsafeEndpoints = parsedArgs.AllowInsecureEndpoints; _eventSchema = string.IsNullOrWhiteSpace(parsedArgs.EventSchema) ? "improbable" : parsedArgs.EventSchema; return(this); }
public object GetAccounts(string userId) { AnalyticsConfig cfg = AnalyticsConfig.Current; AnalyticsConfigUser user = cfg.GetUserById(userId); if (user == null) { return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.NotFound, "User not found."))); } GoogleService google = GoogleService.CreateFromRefreshToken( user.Client.ClientId, user.Client.ClientSecret, user.RefreshToken ); var response1 = google.Analytics.Management.GetAccounts(new AnalyticsGetAccountsOptions(1000)); var response2 = google.Analytics.Management.GetWebProperties(new AnalyticsGetWebPropertiesOptions(1000)); var response3 = google.Analytics.Management.GetProfiles(new AnalyticsGetProfilesOptions(1000)); var accounts = response1.Body.Items; var webProperties = response2.Body.Items; var profiles = response3.Body.Items; var body = new Models.Api.Selector.UserModel(user, accounts, webProperties, profiles); return(body); }
public void FallBackToDefaultConfigurationGracefully() { var config = new AnalyticsConfig(""); Assert.AreEqual(config.GetCategory("c", "t"), DefaultEventCategory); Assert.True(config.IsEnabled("c", "t")); }
public static void SetLatency(int value) { #if UNITY_EDITO Debug.Log("SetLatency"); #elif UNITY_IPHONE _SetLatency(value); #elif UNITY_ANDROID AnalyticsConfig.CallStatic("setLatencyWindow", (long)value); #endif }
//设置是否对日志信息进行加密, 默认false(不加密). //value 设置为true, SDK会将日志信息做加密处理 public static void SetLogEncryptEnabled(bool value) { #if UNITY_EDITO Debug.Log("SetLogEncryptEnabled"); #elif UNITY_IPHONE _SetEncryptEnabled(value); #elif UNITY_ANDROID AnalyticsConfig.CallStatic("enableEncrypt", value); #endif }
public void InitClientsWithoutHttpClient() { var config = new SearchConfig("AppID", "APIKey"); Assert.Throws <ArgumentNullException>(() => new SearchClient(config, null)); var analyticsConfig = new AnalyticsConfig("AppID", "APIKey"); Assert.Throws <ArgumentNullException>(() => new AnalyticsClient(analyticsConfig, null)); var insightConfig = new InsightsConfig("AppID", "APIKey"); Assert.Throws <ArgumentNullException>(() => new InsightsClient(insightConfig, null)); }
public object GetStatus() { AnalyticsConfig cfg = AnalyticsConfig.Current; return(new { clients = new { count = cfg.GetClients().Length, add = true }, users = new { count = cfg.GetUsers().Length, add = true, authenticate = true } }); }
public IAnalyticsSender Build() { _config = _config ?? new AnalyticsConfig(); if (_endpoint != null && !string.IsNullOrEmpty(_gcpKey)) { if (_endpoint.Scheme != Uri.UriSchemeHttps && !_allowUnsafeEndpoints) { throw new ArgumentException( string.Format(_insecureProtocolExceptionMessage, _endpoint.Scheme)); } return(new AnalyticsSender(_endpoint, _config, _environment, _gcpKey, _eventSource, _eventSchema, _maxQueueTime, _maxQueueSize, _dispatchExceptionStrategy, _httpClient)); } return(new NullAnalyticsSender()); }
async void player_Loaded(object sender, RoutedEventArgs e) { var configFileUrl = new Uri("ms-appx:///AudienceInsightConfig.xml"); // Audience Insight config var batchingConfig = await BatchingConfigFactory.Load(configFileUrl); var dataClient = (RESTDataClient)batchingConfig.BatchAgent; dataClient.AdditionalHttpHeaders.Add("Authorization-Token", "{2842C782-562E-4250-A1A2-F66D55B5EA15}"); var batchinglogAgent = new BatchingLogAgent(batchingConfig); var aiLoggingTarget = new AudienceInsightLoggingTarget(batchinglogAgent); Microsoft.Media.Analytics.LoggingService.Current.LoggingTargets.Add(aiLoggingTarget); // Player Framework analytics config var analyticsConfig = await AnalyticsConfig.Load(configFileUrl); var analyticsPlugin = new AnalyticsPlugin(analyticsConfig); var adaptivePlugin = player.Plugins.OfType <AdaptivePlugin>().FirstOrDefault(); var adaptiveMonitorFactory = new AdaptiveMonitorFactory(adaptivePlugin.Manager); var edgeServerMonitor = new EdgeServerMonitor(); analyticsPlugin.AdaptiveMonitor = adaptiveMonitorFactory.AdaptiveMonitor; analyticsPlugin.EdgeServerMonitor = edgeServerMonitor; player.Plugins.Add(analyticsPlugin); // Audience Insight ad tracking config analyticsPlugin.AnalyticsCollector.LoggingSources.Add(new AdvertisingLoggingSource(player.GetAdHandlerPlugin().AdHandlerController)); // -or- //LoggingService.Current.LoggingSources.Add(new AdvertisingLoggingSource(player.GetAdHandlerPlugin().AdHandlerController)); }
void player_Loaded(object sender, RoutedEventArgs e) { var configFileUrl = new Uri("/PlayerFrameworkSample;component/AudienceInsightConfig.xml", UriKind.Relative); // Audience Insight config var batchingConfig = Microsoft.AudienceInsight.BatchingConfigFactory.Load(configFileUrl); // Add custom header(s) var dataClient = (RESTDataClient)batchingConfig.BatchAgent; dataClient.AdditionalHttpHeaders.Add("Authorization-Token", "{2842C782-562E-4250-A1A2-F66D55B5EA15}"); var batchinglogAgent = new BatchingLogAgent(batchingConfig); var aiLoggingTarget = new AudienceInsightLoggingTarget(batchinglogAgent); Microsoft.VideoAnalytics.LoggingService.Current.LoggingTargets.Add(aiLoggingTarget); // Player Framework analytics config var analyticsConfig = AnalyticsConfig.Load(configFileUrl); var analyticsPlugin = new AnalyticsPlugin(analyticsConfig); var adaptivePlugin = player.Plugins.OfType <AdaptivePlugin>().FirstOrDefault(); analyticsPlugin.AdaptiveMonitor = new AdaptiveMonitor(adaptivePlugin.SSME); analyticsPlugin.EdgeServerMonitor = new EdgeServerMonitor(); player.Plugins.Add(analyticsPlugin); // Audience Insight ad tracking config analyticsPlugin.AnalyticsCollector.LoggingSources.Add(new AdvertisingLoggingSource(player.GetAdHandlerPlugin().AdHandlerController)); // -or- //LoggingService.Current.LoggingSources.Add(new AdvertisingLoggingSource(player.GetAdHandlerPlugin().AdHandlerController)); }
internal AnalyticsSender(Uri endpoint, AnalyticsConfig config, AnalyticsEnvironment environment, string gcpKey, string eventSource, TimeSpan maxEventQueueDelta, int maxEventQueueSize, IDispatchExceptionStrategy dispatchExceptionStrategy, HttpClient httpClient) { _endpoint = endpoint; _config = config; _environment = environment; _gcpKey = gcpKey; _eventSource = eventSource; _maxEventQueueSize = maxEventQueueSize; _dispatchExceptionStrategy = dispatchExceptionStrategy; _httpClient = httpClient; Task.Factory.StartNew(async() => { while (true) { await DispatchEventQueue(); await Task.Delay(maxEventQueueDelta, _timedDispatchCancelTokenSrc.Token); } }, _timedDispatchCancelTokenSrc.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public void HandleConfigPrecedenceRulesCorrectly() { var config = new AnalyticsConfig(_configString); // d.e should route to *.* as there is no match Assert.False(config.IsEnabled("d", "e")); Assert.AreEqual(DefaultEventCategory, config.GetCategory("d", "e")); // d.a should route to *.a as there is not a better match Assert.True(config.IsEnabled("d", "a")); Assert.AreEqual("function", config.GetCategory("d", "a")); // b.d should route to b.* as there is not a better match Assert.True(config.IsEnabled("b", "d")); Assert.AreEqual("function-2", config.GetCategory("b", "d")); // b.a should route to b.* as a match on class is preferred on a match on type (i.e. b.* > *.a) Assert.True(config.IsEnabled("b", "a")); Assert.AreEqual("function-2", config.GetCategory("b", "a")); // b.c should route to b.c as it is an exact match Assert.True(config.IsEnabled("b", "c")); Assert.AreEqual("function-3", config.GetCategory("b", "c")); }
public AnalyticsSenderBuilder With(AnalyticsConfig config) { _config = config ?? throw new ArgumentNullException(); return(this); }
public object GetData(int pageId, string period = "yesterday") { IPublishedContent content = Umbraco.Content(pageId); if (content == null) { return(Request.CreateResponse(JsonMetaResponse.GetError("Page not found or not published."))); } IPublishedContent site = GetSiteNode(content); if (site == null) { return(Request.CreateResponse(JsonMetaResponse.GetError("Unable to determine site node."))); } AnalyticsProfileSelection selection = site.Value("analyticsProfile") as AnalyticsProfileSelection; // Get a reference to the configuration of this package AnalyticsConfig config = AnalyticsConfig.Current; string profileId = null; GoogleService service = null; if (selection != null && selection.IsValid) { profileId = selection.Profile.Id; AnalyticsConfigUser user = config.GetUserById(selection.User.Id); if (user != null) { service = GoogleService.CreateFromRefreshToken( user.Client.ClientId, user.Client.ClientSecret, user.RefreshToken ); } } // Fallback to app settings (if specified) if (service == null && config.HasAppSettings) { profileId = config.AppSettings.AnalyticsProfileId; service = GoogleService.CreateFromRefreshToken( config.AppSettings.GoogleClientId, config.AppSettings.GoogleClientSecret, config.AppSettings.GoogleRefreshToken ); } if (String.IsNullOrWhiteSpace(profileId) || service == null) { return(Request.CreateResponse(JsonMetaResponse.GetError("The Analytics package is not configured."))); } AnalyticsDataMode mode = content.Id == site.Id ? AnalyticsDataMode.Site : AnalyticsDataMode.Page; Period p = Period.Parse(period); return(new { period = p, page = new { id = content.Id, name = content.Name, url = content.Url }, history = GetHistory(service.Analytics, profileId, content, mode, p) }); }
/// <summary> /// Creates a new instance of AnalyticsPlugin. /// </summary> /// <param name="analyticsConfig">The required analytics config object used to control what kind of analytics data should be collected.</param> public AnalyticsPlugin(AnalyticsConfig analyticsConfig) { AnalyticsConfig = analyticsConfig ?? new AnalyticsConfig(); MediaData = new Dictionary <string, object>(); SessionData = new Dictionary <string, object>(); }