Table of Contents

Class Ga4TagTracker

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

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

Gets a value indicating whether the device is mobile, or null to tell it from UserAgent.

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

int

Methods

Track(Ga4TagEvent, CancellationToken)

Sends an event.

public Task Track(Ga4TagEvent ga4Event, CancellationToken cancellationToken)

Parameters

ga4Event Ga4TagEvent

The event.

cancellationToken CancellationToken

The 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

ga4Events IEnumerable<Ga4TagEvent>

The events.

cancellationToken CancellationToken

The 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

trackEvents IEnumerable<TrackEvent>

The events.

cancellationToken CancellationToken

The 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

ga4Event Ga4TagEvent

The event.

logger ILogger

The logger a failure goes to.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.