Reputation: 7
I am new to PHP but learning slowly. Problem I have is including Google Analytics in my header.
I have created a separate php file for the code but my issue is including this in the PHP HEADER file below:
I believe that the issue is the @$content[1] .=' tag - but I need to include this as this is how my site is built.
How would I put the Google Analytics code before the tag without confusing the php code in the file.
Thanks in advance. (I would ask my developer but I want to learn myself).
HEADER FILE PHP CODE BELOW:
<?php
@$content[1] .='
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title</title>
<link id="www-core-css" rel="stylesheet" href="template/css/core.css">
<link id="www-core-css" rel="stylesheet" href="template/css/style.css">
</script></head>
<body>
<div id="page" class=""> </div>
<div id="masthead-container">
<div id="masthead" class="">
<a href="index.php">
<button id="logo" class="master-sprite" title="Online ePub Builder"></button>
</a>
<div align="right">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6078741672481332";
/* UK 1 */
google_ad_slot = "5428463210";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>';
if(is_login()) {
$content[1] .='<div id="masthead-utility">
Hello, <a href="user.php">'.$_SESSION['uidrealname'].'</a>
<a href="logout.php">Sign Out</a>
</div>';
} else {
$content[1] .='<div id="masthead-utility">
<a href="login.php">Create Account</a>
or
<a href="login.php">Sign In</a>
</div>';
}
$content[1] .=' <div id="masthead-nav-user">
<a href="help.php">Help</a>
<a href="guide.php">FREE Guide</a>
</div>
<div id="masthead-nav-main">
<a href="new.php">New Book</a>
'.(is_login() ? '<a href="books.php? u='.$_SESSION['uid'].'">My Books</a>' : '').'
</div>
<div id="masthead-end"></div>
</div>
</div>
<div id="baseDiv">
<div id="homepage-main-content" class="">';
?>
Upvotes: 0
Views: 3102
Reputation: 683
Tip i would put the code in footer and not the header so you get the true page load time
Upvotes: 0
Reputation: 502
you just need to put Google analytic script between <head>
</head>
tags like,
<head>
<script type="text/javascript">
//past your Google analytic script here
</script>
</head>
Upvotes: 0
Reputation: 3500
Get the file content:
$trackingCode = file_get_contents('yourFile');
Then just add this into your string just before the end of your head like so:
<link id="www-core-css" rel="stylesheet" href="template/css/style.css">
</script>
'.$trackingCode.'
</head>
Upvotes: 1
Reputation: 11951
I think you mean that you want the Google analytics JavaScript in the html <head>
tag - the PHP header is generally understood to be the HTTP headers sent to the client's browser.
If this is the case, just put the google analytics script somewhere before the closing head tag </head>
.
P.s. you currently have a random </script>
tag with no opening tag just before your closing </head>
- delete it!
Upvotes: 0