Class Ga4TagTracker
Provides a tracker that sends events the way a web page's Google tag (gtag.js) does, with no API secret.
public class Ga4TagTracker : TrackerBase, IGa4TagTracker, ITracker
- Inheritance
-
Ga4TagTracker
- Implements
- Inherited Members
Properties
IsMobile
public bool? IsMobile { get; init; }
Property Value
- bool?
SessionCount
Gets or sets the number of the user's sessions, this one included.
public required int SessionCount { get; set; }
Property Value
Methods
Track(Ga4TagEvent, CancellationToken)
Sends an event.
public Task Track(Ga4TagEvent ga4Event, CancellationToken cancellationToken)
Parameters
ga4EventGa4TagEventThe event.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- Exception
The request failed, with ThrowExceptionOnError.
Track(IEnumerable<Ga4TagEvent>, CancellationToken)
Sends events, one request each, in order.
public Task Track(IEnumerable<Ga4TagEvent> ga4Events, CancellationToken cancellationToken)
Parameters
ga4EventsIEnumerable<Ga4TagEvent>The events.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- Exception
The request failed, with ThrowExceptionOnError.
Track(IEnumerable<TrackEvent>, CancellationToken)
Sends events.
public override Task Track(IEnumerable<TrackEvent> trackEvents, CancellationToken cancellationToken)
Parameters
trackEventsIEnumerable<TrackEvent>The events.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
Each event's parameters are sent as its properties, one request each.
Exceptions
- Exception
The request failed, with ThrowExceptionOnError.
TryTrack(Ga4TagEvent, ILogger, CancellationToken)
Sends an event. The send logs a failure as an error, and throws it only with ThrowExceptionOnError; what it throws then is logged here at Debug.
public Task TryTrack(Ga4TagEvent ga4Event, ILogger logger, CancellationToken cancellationToken)
Parameters
ga4EventGa4TagEventThe event.
loggerILoggerThe logger a failure goes to.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.