How do I add a script to the head section of each page?

Permalink 1 user found helpful
I want to add some Google DFP code to the head section across my entire concrete5 site. I have the code but can't find or access the header area. How do I do this?

 
bbeng89 replied on at Permalink Reply
bbeng89
An easy way would be to go to yoursite/index.php/dashboard/system/seo/tracking_codes/ and add the code there.

Another way is if your theme has a header file that is included on every page you could do
$this->addHeaderItem('code here');
Scafidi454 replied on at Permalink Reply
Scafidi454
Hi,

I just tried this, but it's not working. This is in my "header.php" under /concrete***/updates/themes/elements:

<?php defined('C5_EXECUTE') or die("Access Denied.");
$this->addHeaderItem('analyticstracking.php');
$this->inc('elements/header_top.php');
$as = new GlobalArea('Header Search');
$blocks = $as->getTotalBlocksInArea();
$displayThirdColumn = $blocks > 0 || $c->isEditMode();

?>

<header>
Scafidi454 replied on at Permalink Reply
Scafidi454
I was able to get the code to pick up the home page by adding the script after the <head> tag, but the problem now is that there is no granularity between pages (i.e. changing pages still reports that users are on the root directory in analytics).

I've tried modifying each page's "page header" blocks to include this code, but it doesn't work.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-xxxxxxxx-x', 'auto');
ga('send', 'pageview');

</script>
pilipala replied on at Permalink Reply
pilipala
I'm not sure what you are trying to do with your tracking code, but would the Header Extra Content page attribute be of any help?

http://legacy-documentation.concrete5.org/tutorials/add-tracking-co...
Scafidi454 replied on at Permalink Reply
Scafidi454
The header extra content didn't help; it just inserts the code in the header or footer (which you can see), and doesn't initiate any tracking on analytics.

I just figured out that my page themes don't all update with the design function; so, maybe after updating them it'll work (as I mentioned, I have it working on the root dir/home page).

I'll keep you all posted.
pilipala replied on at Permalink Reply
pilipala
It looks like your problem then isn't adding script to the header of each page, which is what this thread is about. Possibly if you start a new thread specifically about the problem that you're having, there might be someone in the community who can give you some help. I am not sure why the GA wouldn't be working on your site, but someone else might know the answer.
Scafidi454 replied on at Permalink Reply
Scafidi454
Seems to be working now, after having changed the theme on each page to match that of the home page (Elemental), and put the script in the very first container below the global header.

By doing this, I am now able to see the granular information (which page a person is viewing).
pilipala replied on at Permalink Reply
pilipala
Good to hear it's working now!
beachdude replied on at Permalink Reply
Thanks!
bbeng89 replied on at Permalink Reply
bbeng89
No problem! Did that solve your problem? If so, don't forget to mark "Best Answer". Thanks!