Redirecting after tracking has completed

I have a page that handles permalinks and redirect to their current locations.
I want to track an pageview when a visitor hits that page, and then redirect to the largest location.

Currently my strategy is too wait long enough, but it may be too long and annoying for the user.

We’re using this code:

<%@ Page Title="Link" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" Inherits="SharpCrafters.Internal.Web.AspNet.LinkPage" CodeBehind="Link.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadPlaceHolder" runat="Server">
    <meta http-equiv="refresh" content="3;url=<%=HttpUtility.HtmlAttributeEncode( this.LinkUrl)%>" />
    <meta http-equiv="robot" content="noindex" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TitlePlaceHolder" runat="Server">
        <h1>Redirecting</h1>
</asp:Content>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder" runat="server">
    <p>
                You will be redirected to <a href="<%=HttpUtility.HtmlAttributeEncode( this.LinkUrl)%>">
                    <%=HttpUtility.HtmlEncode(this.LinkUrl)%></a>.</p>
</asp:Content>

How can I create a JavaScript that redirects as soon as Matomo has registered the pageview?

Hi @gfraiteur
I think you could use the sendbeacon in order to achieve this: