Contact tracking: optional custom parameters and transfer of url in mt() event

Your software
My Mautic version is: 3.1.0
Angular

Your problem
I am currently using the standard script:

<script>
    (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
        w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
        m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://myurl/mtc.js','mt');

    mt('send', 'pageview');
</script>

I want to track every user login to the site (user parameters must be displayed in the tracking), as well as every step of registering a new user (entering email, entering name and surname, etc.).

As far as I understand, I have to add a function to the standard script (or instead of it), which I will call in different parts of my project (user login, first login step, second login step, etc.), in which there will be something like

function sendEvent(email, name, surname, address, ...) {
mt('send', 'pageview', {email, name, surname, address});
}

I can’t figure out how to write such a function, how it should interact with the standard script above (it also has mt() event) and how to make parameters optional (for example, when registration has only email)

I want get url ‘https://myurl/mtc.js’ from backend (appsettings.json). How can this be implemented? Is it possible to transfer the url to the mt() event as a parameter?

Hi, there is an article about this:
https://www.mautic.org/blog/developer/tracking-visitor-data-by-smart-url

joeyk, thank you for your answer, I got the 1st part. The question with transferring U(url) parameter from main function to mt remains open.