'$tracking_code'
ist just a string. It closes <head>
automatically. So, no, it doesn’t come after the head
, you just failed to use source view. Firebug and similar tools show just the rendered DOM, that’s not good enough.
Fix: echo $tracking_code;
.