We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Add code snippets to site

How Do I?

Todd U's avatar
Todd U
2 posts
4 years ago
Todd U's avatar Todd U

Hi, I have zero experience with Expression Engine, but our client has a site built in it and we want to add short Google Tag Manager code snippets (<head> and <body>) to every page. Does anybody have a simple way to do that task? Thank you!

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

Todd, Welcome. You’ll need to look through the templates and see how they are constructed. If the person who built the site used layouts, embeds, or partials for the head section, then you may only have to update one location. Otherwise, you’ll just need to find where they added the <body> and <head> sections. Start with the template docs to understand how they work: https://docs.expressionengine.com/latest/templates/overview.html .

A couple other good resources would be Justin’s article on understanding templates from his Intro to EE course: https://u.expressionengine.com/course/introduction-to-building-an-expressionengine-site/templating-intro-templates-template-groups-staying-dry, and Doug’s Templating lesson if video is more your thing from his Intro to EE video course: https://u.expressionengine.com/course/getting-started-with-expressionengine-video-course/getting-started-with-expressionengine-using-file-fields-part-2-templating. hope that helps.

? 1
       
Rob Allen's avatar
Rob Allen
3,105 posts
4 years ago
Rob Allen's avatar Rob Allen

You may need to protect site visitors by only including Googles surveillance code behind a consent if it leaks any personal information to Google (hint - it nearly always does). EE has a full consent mechanism built in, see https://docs.expressionengine.com/latest/add-ons/consent.html#consent - this will give visitors the option whether to allow surveillance or not, and is required if visiting the site from the EU.

Consent is quite technical to set up, if you can’t do it yourself I’d recommend seeking some assistance.

? 1
       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

Todd, Just wanted to follow up and see if you were able to figure this out and get your snippets inserted.

       
vw000's avatar
vw000
482 posts
4 years ago
vw000's avatar vw000

Go to your EE control panel and create a template variable (or upload it through your favorite IDE editor).

Let’s say you call it “google-tags”. Insert your Google HTML or JS code inside.

Then go to your template pages and put the variable in the headers:

{google-tags}

The code will now be displayed on every page, and you can update it in one single place if you require it in the future.

Now to second what Rob mentioned, be aware of privacy issues. If this is a business or commercial sites, it’s not very user-friendly to transfer visitors/customers data to a third party like Google without their consent.

Second of all, third-party analytics are very much useless today.

You might mention this to your customer. The stats will be very broken because tons of users use ad blockers today and most browsers have build in some tracking protection.

That means almost all Google code is already blocked. If this is a site towards geek or technology users, it’s even worst. Your analytics will miss a huge amount of traffic.

Your best option is to do analytics on the server side without leaking it to a third party. A local solution like Piwik, Webalizer, Open Analytics or something else should do the trick, and you can get full analytics of people hitting your server.

Using your local logs might be harder to set up once, but it’s faster (you are not using a third-party code to load from another server…), it’s private (data stays in your server, and you control it) and it’s more precise (it will log all traffic).

       
Rob Allen's avatar
Rob Allen
3,105 posts
4 years ago
Rob Allen's avatar Rob Allen

vw000 makes a good point about analytics, I’d add that there are privacy friendly 3rd party analytics services around such as https://usefathom.com/ and https://plausible.io/ - these don’t collect any personal information whatsoever so you usually don’t need to get consent.

       
Todd U's avatar
Todd U
2 posts
4 years ago
Todd U's avatar Todd U

Thank you all! Our deadline got moved back so I’ll just be getting back to this project next week. Our client hasn’t yet been able to get us FTP access to their host. Am I able to do this work strictly within EE via Developer -> Templates in the control panel?

       
vw000's avatar
vw000
482 posts
4 years ago
vw000's avatar vw000

You should be able to edit the templates directly from EE, but personally I prefer to use an external IDE code editor and just upload the template files. If you don’t have access to FTP server, then editing through the control panel should be fine for now.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.