Absolutely you can keep your analytics code Theme-agnostic.
Most analytics code is simply a script, and scripts can (and should) be enqueued using proper hooks. In this case, the relevant hooks require nothing more than Theme support for two all-but-universal template tags: wp_head() and wp_footer().
Keeping the analytics code Theme-agnostic will require writing (or using an existing) Plugin - but not a complicated one, at all. Essentially, it would be simply a hook call, and an associated callback to define the analytics code. Something like this (assuming you've got your analytics code in a file called \js\analytics.js:
<?php
/**
* Plugin Name: Custom Analytics Code
*/
function someprefix_enqueue_analytics_code() {
wp_enqueue_script(
'someprefix_analytics', // script handle
get_template_directory_uri() . '/js/analytics.js', // script URL
'', // dependencies; if any: array( dep1, dep2... )
'', // version number to append to URL query string
true // output script in the footer
);
}
add_action( 'wp_enqueue_scripts', 'someprefix_enqueue_analytics_code' );
?>
And that's it!