I'm trying to implement a tracking pixel in Blazor to track the open rate of a newsletter list. To do so I thought that I had to work on circuits so I realized a little circuit counter to investigate this possibility:
public class CircuitCounter : CircuitHandler, ICircuitCounter
{
private long circuitCount = 0;
public override Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
{
long updatedCircuitCount = Interlocked.Increment(ref circuitCount);
NotifyUpdatedCircuitCount(updatedCircuitCount);
return base.OnCircuitOpenedAsync(circuit, cancellationToken);
}
private void NotifyUpdatedCircuitCount(long updatedCircuitCount)
{
CircuitCountChanged?.Invoke(this, updatedCircuitCount);
}
public long CurrentCircuitCount => Interlocked.Read(ref circuitCount);
public event EventHandler<long> CircuitCountChanged;
}
View of the counter:
@page "/counter"
@inject CircuitHandlers.ICircuitCounter circuitCounter
@implements IDisposable
<h1>Circuit counter</h1>
<p>Circuits opened: @currentCircuitCount</p>
@code {
long currentCircuitCount;
protected override void OnInitialized()
{
currentCircuitCount = circuitCounter.CurrentCircuitCount;
circuitCounter.CircuitCountChanged += UpdateCircuitCount;
}
private void UpdateCircuitCount(object sender, long circuitCount)
{
InvokeAsync(() =>
{
currentCircuitCount = circuitCount;
StateHasChanged();
});
}
public void Dispose()
{
circuitCounter.CircuitCountChanged -= UpdateCircuitCount;
}
}
The problem is that the counter doesn't go up if I try to send myself an email containing a tracking pixel that looks like this
<img src="localhost:44334/foo" />
My guess at this point is that the attempt to fetch the image from that URL isn't enough to trigger the opening of a new circuit but if that's actually the case I'm a bit lost on how should I proceed instead and I wasn't really able to find anything Blazor related on the internet about this.