Add it to all Confluence pages
You have to use the page layout. → Confluence Administration → Layouts (under Look & Feel) → Create custom (Page Layout under Content Layouts). There you can add the macro to the page layout. This is an example to add the Viewtracker macro at the end of any page:
If you like to add the Viewtracker in the hidden mode, you can use this snippet:
If you like to show your results only to you administrators, you can read this documentation: How can I make a Viewtracker report only visible to administrators?
Add it to specific spaces
You use the same approach but configure the custom page layout in the space(s) you would like to track:
Go to: Space Admin → Layouts (under Look & Feel) → Create custom (Page Layout under Content Layouts) and add the code mentioned above.