Table of Contents

Class Ga4MeasurementTracker

Namespace
Ga4.Trackers.Ga4Measurements
Assembly
VpnHood.Net.Toolkit.dll

Provides a tracker that sends events through Google Analytics 4's Measurement Protocol, which a server or an app uses with an API secret.

public class Ga4MeasurementTracker : TrackerBase, IGa4MeasurementTracker, ITracker
Inheritance
Ga4MeasurementTracker
Implements
Inherited Members

Remarks

Each event gets the session's ID, when there is one, and debug_mode with IsAdminDebugView, unless it has them already. A failed request throws only with ThrowExceptionOnError.

Properties

ApiSecret

Gets the Measurement Protocol API secret of the data stream.

public required string ApiSecret { get; init; }

Property Value

string

IsDebugEndPoint

Gets or sets a value indicating whether the events go to the validation endpoint, which checks them and records nothing.

public bool IsDebugEndPoint { get; set; }

Property Value

bool

Methods

Track(Ga4MeasurementEvent, CancellationToken)

Sends an event.

public Task Track(Ga4MeasurementEvent ga4Event, CancellationToken cancellationToken)

Parameters

ga4Event Ga4MeasurementEvent

The event.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentException

The event's parameter names collide when case is ignored, with the tracker on.

Exception

The request failed, with ThrowExceptionOnError.

Track(IEnumerable<Ga4MeasurementEvent>, CancellationToken)

Sends events.

public Task Track(IEnumerable<Ga4MeasurementEvent> ga4Events, CancellationToken cancellationToken)

Parameters

ga4Events IEnumerable<Ga4MeasurementEvent>

The events.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentException

ga4Events is empty, with the tracker on, or an event's parameter names collide when case is ignored.

Exception

The request failed, with ThrowExceptionOnError.

Track(IEnumerable<TrackEvent>, CancellationToken)

Sends events.

public override Task Track(IEnumerable<TrackEvent> trackEvents, CancellationToken cancellationToken)

Parameters

trackEvents IEnumerable<TrackEvent>

The events.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentException

trackEvents is empty, with the tracker on, or an event's parameter names collide when case is ignored.

Exception

The request failed, with ThrowExceptionOnError.