/// <summary> /// Tracks the given <paramref name="modules"/> for the current <paramref name="application"/> using the current <see cref="TrackingEngine"/> /// </summary> /// <param name="application">The details of the application making the tracking request</param> /// <param name="modules">The <see cref="ITrackingModule"/>s being used to generate the request</param> public async Task TrackAsync(ITrackingApplication application, IEnumerable <ITrackingModule> modules) { if (!GlobalEnabled || !Enabled) { return; } //Check that we have a valid UserAgent string, if not then load a default one if (UserAgent.IsNullOrWhitespace()) { UpdateUserAgent(application.Name, application.Version); } var request = await CreateRequestAsync(application); await PreProcessAsync(request); List <ITrackingFinalize> requiringFinalization = new List <ITrackingFinalize>(); foreach (var module in modules) { module.PreProcess(request); if (module is ITrackingFinalize) { requiringFinalization.Add(module as ITrackingFinalize); } } await PostProcessAsync(request); var preparedRequest = await PrepareRequestAsync(request, requiringFinalization); OnRequestPrepared(preparedRequest); }
protected async override Task <RestSharp.IRestRequest> CreateRequestAsync(ITrackingApplication application) { var request = new RestSharp.RestRequest("/collect", RestSharp.Method.POST); // Client ID // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters request.AddParameterExclusive("cid", await GetClientIDAsync(application)); // Add application name and version parameters to request // https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide request.AddParameter("an", application.Name.Truncate(150)); request.AddParameter("av", application.Version.Truncate(150)); return(request); }
/// <summary> /// Creates a <see cref="IRestRequest"/> for the given application context /// which will be used to generate the tracking request for the engine. /// </summary> /// <param name="application">The application context which generated the tracking request</param> /// <returns></returns> protected abstract Task <IRestRequest> CreateRequestAsync(ITrackingApplication application);
protected abstract Task <string> CreateNewClientIDAsync(ITrackingApplication application);
/// <summary> /// Gets a unique identifier for the current user /// </summary> /// <param name="application">The application for which the client ID should be retrieved</param> /// <returns>Returns the unique identifier representing the currently active user</returns> /// <remarks> /// Each client ID is unique to a computer, user account, <see cref="ITrackingApplication"/>, <see cref="TrackingEngine"/> and /// tracker ID given by <see cref="GetTrackerID()"/> (provided that the <see cref="CreateNewClientID"/> function returns /// unique values). /// /// If a client ID is not found for the current combination of the above then one will be generated by making a call to /// <see cref="CreateNewClientID"/>. /// </remarks> protected async Task <string> GetClientIDAsync(ITrackingApplication application) { var clientIDKey = string.Format("{0}:{1}:{2}", this.GetType().FullName, application.Name, GetTrackerID()); return(await KeyStore.GetOrFetchObject <string>(clientIDKey, () => CreateNewClientIDAsync(application)).FirstAsync()); }
/// <summary> /// Tracks the given <paramref name="modules"/> for the current <paramref name="application"/> using the <see cref="Default"/> <see cref="TrackingEngine"/> /// </summary> /// <param name="application">The details of the application making the tracking request</param> /// <param name="modules">The <see cref="ITrackingModule"/>s being used to generate the request</param> public static void TrackDefault(ITrackingApplication application, IEnumerable <ITrackingModule> modules) { CheckDefaultSet(); Task.Run(() => Default.TrackAsync(application, modules)); }
/// <summary> /// Tracks the given <paramref name="modules"/> for the current <paramref name="application"/> using the <see cref="Default"/> <see cref="TrackingEngine"/> /// </summary> /// <param name="application">The details of the application making the tracking request</param> /// <param name="modules">The <see cref="ITrackingModule"/>s being used to generate the request</param> public static void TrackDefault(ITrackingApplication application, params ITrackingModule[] modules) { CheckDefaultSet(); Task.Run(() => Default.TrackAsync(application, modules)); }
protected async override Task <string> CreateNewClientIDAsync(ITrackingApplication application) { return(Guid.NewGuid().ToString().ToLower()); }
/// <summary> /// Tracks the given <paramref name="modules"/> for the current <paramref name="application"/> using the current <see cref="TrackingEngine"/> /// </summary> /// <param name="application">The details of the application making the tracking request</param> /// <param name="modules">The <see cref="ITrackingModule"/>s being used to generate the request</param> public async Task TrackAsync(ITrackingApplication application, params ITrackingModule[] modules) { await TrackAsync(application, modules as IEnumerable <ITrackingModule>); }