There is no security risk to modify any theme if you know what you are exactly doing and themes are made by developers and you can customize it.
function add_ga_code()
{
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']); //Update 'UA-XXXXX-X' with valid account id
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
add_action('wp_head', 'add_ga_code');
Add this in your functions.php file located in your theme folder or just put the whole script between head tag before wp_head() of your header.php file which is also located inside your theme folder.