Difference between two HubSpot tracking code implementations

I need help understanding HubSpot tracking codes. Our website currently uses this implementation:

var hub_id = 789012;
var tracking_ver = "2.00";
var hub_domain = "client-portal.app15.hubspot.com";
document.write(unescape("%3Cscript src='" + document.location.protocol + "//" + hub_domain + "/salog.js.aspx' type='text/javascript'%3E%3C/script%3E"));

Now we received a request to implement this second tracking script:

(function(doc, tag, identifier, interval) {
    if (doc.getElementById(identifier)) { return; }
    var scriptTag = doc.createElement(tag);
    var firstScript = doc.getElementsByTagName(tag)[0];
    scriptTag.id = identifier;
    scriptTag.src = '//js.hubspot.com/analytics/' + (Math.ceil(new Date()/interval) * interval) + '/789012.js';
    firstScript.parentNode.insertBefore(scriptTag, firstScript);
})(document, "script", "hubspot-tracker", 300000);

Are these two scripts serving the same purpose or do they handle different tracking functions? Should both be used together or is one replacing the other?

The first script is HubSpot’s legacy tracking code, while the second script is the current recommended implementation. In my experience, switching to the newer script has improved performance and provided more accurate tracking data. A key difference is in their loading methods; the older script uses document.write, which can negatively impact page speed, whereas the new one loads asynchronously. To prevent potential issues with duplicate tracking events, you should replace the old script with the new one.