/**
 * Google tracker initialization
 * @param {string} id measurement ID
 * @return {function} tracker function
 */
export function loadGTAG(id) {

    (function (target, s, domTag, sourceURL) {

        const a = s.createElement(domTag);
        const m = s.getElementsByTagName(domTag)[0];

        a.async = 1;
        a.src = sourceURL;

        m.parentNode.insertBefore(a, m)
    })(document, document, 'script', `https://www.googletagmanager.com/gtag/js?id=${id}`);


    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());

    gtag('config', id);


    return gtag;
}