No this is not the right way to track things.
What I will suggest is to try this.
Create a dummy page on your web server and add default analytics code for site. Then call this page in an inframe and see if things work as expected. If it does then the way you are calling Analytics code has the issue.