Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

StatCounter and Vanilla -- My solution

edited March 2012 in Vanilla 2.0 - 2.8

I've used StatCounter (SC) for years. It's reliable and has a lot of good information. When I started my Vanilla Forum, I couldn't figure out where to place the SC code. I tried placing it in the index.php file, and got an error about an unexpected "<".

After some thrashing around, I decided to turn the index.php into a normal web page.

I went to w3.org and found a section with a Doctype declaration and all the code for a web page. I opened the index.php in Notepad and added the Doctype code at the top of the page, above the mad jumble that was already there. This is the php code that actually does things. You needn't worry about this code; our work will be to add things before and after this code, with one small exception, which is critical.

With this, I was halfway home. This discussion can't use the actual code, so you'll have to look at the code and match it up with my description. Vanilla forum here won't show the html tags properly.

Deleted the line with the title in it, since I didn't want a title to show up.

Deleted the lines with the slash body and slash html -- those will go below, later.

Changed the HTML to html and the BODy to body. This is a convention I use, since this will validate. (It's curious that W3 presents code with capitals when the capitals will give an error during validation.)

CRITICAL: Added a ?> to the end of the php block of code. This closes the php section. The failure to close the php is what was giving the error about an unexpected "<".

Added the StatCounter code after the ?>

Added the
slash body and slash html (These are closing tags)
to the very end.

Saved.

BEGIN review.

You now have a page with -- (Remember, all html tags are lower case.)

Doctype at the top.

a blank head tag with the closing section.

an html tag.

a body tag.

the php code.

a final ?> after the php section.

the Statcounter code.

a closing body tag.

a closing html tag.

END Review.

Went to my Filezilla, deleted the existing index.php online.

Uploaded my amended index.php to the web.

Went online, looked at my forum.

Went to StatCounter, and !Viola! a visit showed up.

QED.

Comments

  • Options

    not good!!!!

    when vanilla is updated it will be overwritten. index.php is a crucial file that shouldn't be messed with.

    Don't edit the core unless you absolutely know what you are doing, and are happy to maintain a fork. Basically don't do it.

    index.php is NOT the master view. The normal master view for xhtml pages is default.master.php. If you want to edit it then copy it from applications/dashboard/views/ to your theme's views folder.

    you are going to end up with all sort of problem with what you have done.

    grep is your friend.

  • Options

    start again what is it you are actually trying to achieve? put a bit of javascript in the head?

    you don't have to do what you have done to do that.

    grep is your friend.

  • Options
    lucluc ✭✭

    x00 said:
    start again what is it you are actually trying to achieve? put a bit of javascript in the head?

    you don't have to do what you have done to do that.

    Indeed, just putting what you need in a "pocket" (pocket plugin) might just be what you need, and it will work across updates.

  • Options
    aeryaery Gtricks Forum in 2.2 :) ✭✭✭

    I have used {literal} tag to put the statcounter code in theme default master view of my forum and same I will recommend to use with my other http://vanillaforums.org/addon/nebula-theme.

    it works like a charm.

    There was an error rendering this rich post.

  • Options
    422422 Developer MVP
    • it's Voila. Not many ppl shout the name of a stringed instrument lol.

    There was an error rendering this rich post.

  • Options

    I did what I did to work around an error in the Vanilla code. My solution may not be the best solution there is, but until I can figure out some other way, it'll do. It has the advantage of being pretty simple to implement.

    What I am trying to do is

    1. Place the StatCounter html snippet at the end of the php code so it will record visits to the page
    2. Get the page to work
    3. Make it as simple as possible

    As for stability across updates, I may or may not keep Vanilla long-term, depending on ease of use, etc. So far, I haven't been impressed with it.

    I purposely wrote Viola in honor of a friend's wife, whose name is Viola.

  • Options
    x00x00 MVP
    edited April 2012

    I did what I did to work around an error in the Vanilla code. My solution may not be the best solution there is, but until I can figure out some other way, it'll do. It has the advantage of being pretty simple to implement.

    Impatience often lead to bad decisions and overcomplicating things because the person is desperate implement something at any cost without understanding, what you call a error could be simple an incorrect approach on your part.

    Take it from me, I'm an experienced developer, this approach is no only not a good solution it is a complete hatchet job. I'm not being facetious, but honest. Every likelihood that you have broken a whole host of functionality. Whether you are aware is besides the point. This is not good at all.

    Also frameworks like vanilla don't just serve one type of content it is not just html. It is not a static system.

    First this software follows MVC
    http://en.wikipedia.org/wiki/Model–view–controller

    You are hatcheting before even the dispatcher is reached. This is nothing to do with a specific framework, you do the equivalent with any system MVC or not it is still a hatchet job. Ask any programmer.

    I think the problem is you are thinking of the index as a template file, in pretty much all modern framework the index file is not a template, it is a low level entry file. If you find a file which by you own admission you don't understand the contents of, then it is probably not the right place.

    I'm pretty surprised you even got it to validate.

    As for stability across updates, I may or may not keep Vanilla long-term, depending on ease of use, etc. So far, I haven't been impressed with it.

    You point about stability is rather ironic point and moot, as you have created an unstable fork of vanilla, which you alone a responsible for maintaining.

    Again if you just want to include some javacript you best bet is to use the pockets plugin
    http://vanillaforums.org/addon/browse/plugins/recent/2

    Give a name, insert the code in the body box, in location put head, for all pages, click save.


    think about it for a minute if every addon hacked up the core, do you think that would make the system more stable? No! That is why the system has a proper api and has event which you can hooked, you can also work with templates and theme, etc but you have to read to documentation.

    Apologise if I was stern, but some lessons are best delivered with fire and brimstone, so they leave a lasting impression. If something is worth doing it is worth doing properly.

    grep is your friend.

Sign In or Register to comment.