Shopify code in the header?

Hey guys,

Im trying to add a Shopify shopping cart to my site. The code in the tutorial below allows to add a buy button, but when clicked, the user is sent to my Shopify account rather than showing the cart inside my website.

This is the tutorial I used:

I did manage to get the cart to show by placing the same code in the header of the page, so I guess some of the code should be in the header. But I’m not sure what part should be in the header, and what should be in the body of the page.