Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

What file to modify for Google Analytics code?

Asked Modified Viewed 8,249 times
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
asked
Junior Member

I am not completely sure if this is the right forum for this question, because it is not about a modification of any system features (so the MOD site seems to be the wrong place), but still about modification of code, well - a file, anyway.

I need to know in what file I should add Google Analytics code before the </HEAD> tag so that it becomes included in all generated pages.
0 replies

13 posts

S
Structor
S
  • Member, joined since
  • Contributed 116 posts on the community forums.
  • Started 11 threads in the forums
answered
Member

I used /templates/footer.php file...
0 replies
H
HobbyMan
H
Just some Guy
  • Veteran Member, joined since
  • Contributed 1,486 posts on the community forums.
  • Started 91 threads in the forums
answered
Veteran Member

You can add code to HEAD without modifying any files, just create a panel and add in your code....

add_to_head("

-- Your Google Code --

");


make sure it's set for public visibility.
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

Excellent! Thanks a lot. Had never thought about a panel.
0 replies
P
PolarFox
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums
answered
Veteran Member

includes/header_includes.php will be better.
For all pages and without any panel.
And with this code of course :)
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

If a solution works without modifying any code, especially not of the core package, then that solution is to prefer. We want as little impact on updateability and upgradeability as possible. In the best of worlds, all mods should be realized as data in the database (possibly with an exception for infusions).
0 replies
B
Basti
B
Basti 10
[PHP-Fusion Crew Member & Admin from June 2008 - December 2010]

http://basti2web.de - Support Site for my infusions
  • Veteran Member, joined since
  • Contributed 1,099 posts on the community forums.
  • Started 32 threads in the forums
answered
Veteran Member

Quote

PolarFox wrote:
includes/header_includes.php will be better.
For all pages and without any panel.
And with this code of course :)


yes, but I would use the footer_includes.php
I think that the site will load faster if the javascript is in the footer.
correct me if i am wrong.
0 replies
H
HobbyMan
H
Just some Guy
  • Veteran Member, joined since
  • Contributed 1,486 posts on the community forums.
  • Started 91 threads in the forums
answered
Veteran Member

That's true, by putting javascript in the footer you can shave of a few milliseconds, but the difference will not be noticeable to most.


--
Edited by HobbyMan on 30-05-2010 15:34,
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

I am still trying to get the panel to work. But I would probably have had the same problem if I had put it in the footer instead:

I have input

[b]add_to_head("[/b]<!-- Google Analytics START -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16649074-1']);
_gaq.push(['_trackPageview']);
</script>
<script type="text/javascript">
document.onclick = function(event) {
    event = event || window.event;
    var target = event.target || event.srcElement,
        targetElement = target.tagName.toLowerCase();
    if (targetElement == "a") {
        var href = target.getAttribute("href"),
            urlHost = document.domain.replace(/^www\./i,"");
        var urlPattern = "^(?:https?:)?\/\/(?:(?:www)\.)?" + urlHost + "\/?";
        eventCheck(href,urlPattern);
    }
    function eventCheck(href,urlPattern){
        if ((href.match(/^https?\:/i)) && (!href.match(urlPattern))){
            if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) {
                _gaq.push(["_trackPageview","/download/" + href]);
            } else {
                _gaq.push(["_trackPageview","/exitlink/" + href]);
            }
        } else if (href.match(/^mailto\:/i)) {
            _gaq.push(["_trackPageview","/mailto/" + href.substr(7)]);
        } else if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) {
            _gaq.push(["_trackPageview","/download/" + href]);
        }
    }
};
</script>
<script type="text/javascript">
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<!-- Google Analytics END -->[b]");[/b]


and get the following fault code:

Parse error: syntax error, unexpected T_STRING in /hsphere/local/home/mydomain/mydomain.com/themes/templates/panels.php(48) : eval()'d code on line 2

The Google code itself should be ok.
Maybe I do not understand how to use the PHPFusion-function add_to_head("");??? Or adding PHP to a panel???
0 replies
H
HobbyMan
H
Just some Guy
  • Veteran Member, joined since
  • Contributed 1,486 posts on the community forums.
  • Started 91 threads in the forums
answered
Veteran Member

Extract google_code.js from attached file and load to your root directory.

Then create a public access panel with the following code and enable, that should do it.

add_to_head("
   <script type='text/javascript' src='".BASEDIR."google_code.js'></script>
");
Edited by HobbyMan on 02-06-2010 00:43,
HobbyMan attached the following file:
google_code.zip [No information available / 0 Downloads]
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

I got rid of the fault code but no js-code was added to the head on the pages :(

(and yes, the panel is active and public).
Edited by etxgmg on 02-06-2010 19:44,
0 replies
H
HobbyMan
H
Just some Guy
  • Veteran Member, joined since
  • Contributed 1,486 posts on the community forums.
  • Started 91 threads in the forums
answered
Veteran Member

I tested it and it works fine...
HobbyMan attached the following file:
googletest.jpg [No information available / 0 Downloads]
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

Well, thanks very much for your support, but it does not work for me (I do exactly the same), but now I also tried to put the same code in the includes/footer_includes.php and then I get the same result as you do. I would rather use the panel, but this is also possible of course (just more modding-work at every update/upgrade and risk for unaccidental removal).
0 replies
E
etxgmg
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

It worked well with

add_to_head("

script with some " replaced by '

");

in the includes/footer_includes.php file. Thanks for great support!

However, in order to get Google Analytics to work correctly, I now also need to include some Javascript tracker code on the <input> button on the contact.php form, this:

onClick="_gaq.push(['_trackPageview', '/mal/formular/kontaktaoss']);"

How should I do that?
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 13 posts
  • Votes 0 votes
  • Topic users 5 members

5 participants

E
E
etxgmg 10
  • Junior Member, joined since
  • Contributed 20 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
H
H
Just some Guy
  • Veteran Member, joined since
  • Contributed 1,486 posts on the community forums.
  • Started 91 threads in the forums
B
B
Basti 10
[PHP-Fusion Crew Member & Admin from June 2008 - December 2010]

http://basti2web.de - Support Site for my infusions
  • Veteran Member, joined since
  • Contributed 1,099 posts on the community forums.
  • Started 32 threads in the forums
S
S
  • Member, joined since
  • Contributed 116 posts on the community forums.
  • Started 11 threads in the forums
P
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet