New Web Analytics - how to place the JS code when using WordPress?

Hello all, new user of the new (free) Analytics service.

I have my beacon JS code which wants to be placed “just above the </body> tag on each page you want to measure”. This is my trouble. I don’t write HTML pages from clean sheets, I’m on WordPress and I write in a template. I put the beacon code on a handful of my site’s pages as a test, at the bottom of the code/text I write for the pages, but when I bring up one of those pages and view the rendered source, that bit of JS is nowhere near the closing body tag, all my sidebar code and other things come after it. Does this matter? It is inside the body section, just not at the end of it.

I have SFTP access to my files on WP’s server, but there aren’t HTML files in there that I can get at, just PHPs and my media files. (I pay WP to try to avoid this sort of detail… please don’t judge me too harshly, I want to write content, not code.) I have done some previous modification to footer.php and so on, but I’m flummoxed as to what to do with this new bit of code, where it should go and how to get it there. All I’m seeing on my analytics page is 0 visits and 0 page views, and while this isn’t a high-traffic site, I’ve made sure to click on a few pages with the beacon from an un-logged-in browser to get something for Cloudflare to count. How fast should this be happening? There’s a selection for “last 30 minutes” so if I’ve waited for an hour or two, wouldn’t my own hits (at least) show up? This is why I think the beacons aren’t working yet, but I don’t know, and so here I am.

Am I dead in the water because I use a WordPress template instead of writing my pages from scratch?

I’d be grateful for any thoughts or other assistance. Sure would love to get rid of Google Analytics in favour of this, if I can get it to work. My other beacons (search engine verifications) have a one-little-html-file placement in the HTDOCS folder, which seems much simpler than code-on-every-page to me, but perhaps it has to do with the enhanced privacy priority here.

Thanks again for any replies.

Adding it as an HTML block in a page or three won’t give you analytics for the entire site.

This plugin looks very popular for doing the very thing you need to do:

2 Likes

I know I wasn’t getting data on the entire site, but I didn’t want to do the work on all the pages individually until I knew it was set up properly on a small subset.

That plugin is exactly what I needed, thank you so much for aiming me at it. Problem solved.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.