Adds Google Tag Manager to the application and manages communication with GTM JavaScript (data-layer).
HxGoogleTagManager
and related components are distributed in a separate NuGet package: Havit.Blazor.GoogleTagManager.
Install GTM support through application startup:
builder.Services.AddHxGoogleTagManager(options =>
{
builder.Configuration.Bind("HxGoogleTagManager", options);
});
Method | Returns | Description |
---|---|---|
InitializeAsync() | Task |
Initializes the GTM support.
Called automatically within first Push call (incl. HxGoogleTagManagerPageViewTracker calls).
To be used explicitly only in those rare cases when you want to initialize GTM without pushing any data. |
PushAsync(object data) | Task |
Push generic data to GTM data-layer (using regular JSON-serialization). |
PushEventAsync(string eventName, object eventData) | Task |
Push event to GTM data-layer. |
PushPageViewAsync(object additionalData) | Task |
Push page-view to GTM data-layer.
Consider using HxGoogleTagManagerPageViewTracker instead of manual handling. |
Install GTM support through application startup (see above) and add HxGoogleTagManagerPageViewTracker
to App.razor
or MainLayout.razor
<HxGoogleTagManagerPageViewTracker />