How can I add a analytics script into the header of my community?

To start off with a theme, you need to install it, have you tried doing that? Check out Installing a theme or theme component for info on how to do that.