I wish to track when a user log in their account in my WordPress website with GA4 (Google Analytics 4), so I used the hook 'wp_login', as you can see in the snippet below that I added to functions.php file, but it doesn't work. I tried the hook alone (to create a cookie) and it works fine and I tried the code inside the function 'gal' alone and it works fine.
add_action('wp_login', 'gal',90);
function gal(){
echo "<script>dataLayer.push({event: 'login'});</script>";
}