Search code examples
google-analyticsgoogle-tag-managersteam

Google Analytics 4: Is it possible to make the new gtag code work with the old analytics.js?


My issue is with the static GA code on the Steam store page.

Steam supports only the analytics.js implementation, and there is no way for me to change the code to a newer GA4 implementation.

All that Steam allows to game developers is to change the tracking id for the store page, but they still use the old analytics.js:

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-xxxxxx-1', 'auto', {
        'sampleRate': 0.4               });
    ga('set', 'dimension1', true );
    ga('set', 'dimension2', 'External' );
    ga('set', 'dimension3', 'application' );
    ga('set', 'dimension4', "application\/app" );
    ga('send', 'pageview' );

</script>

Is it possible to use the new GA4 gtag measurement ID with this old implementation? Would using it instead of the UA-xxxxxx-1 in analytics.js work?


Solution

  • To answer your question, it is not enough to change the code from UA- to G- as everything else in the snippet and events is also different.

    Anyway, the best solution is not to replace the code but to trace in parallel with both, then leave the 'old' UA and add the new trace with GA4. In this way you do not lose the history, moreover the two systems are completely different and not comparable.