Forums / Templates, Stylesheets, Page Layout / Adding tracking script to main page

Adding tracking script to main page

Views: 1,886

Results 1 to 20 of 23
4 Jun 2011, 8:25 PM
#1
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Adding tracking script to main page

I am using the latest version of Zen Cart.

I want to add a **hitsniffer tracking script **on the main page.

I am not sure where or how to do this as the info says place this (script) before end of the [/body] tag.

Can anyone translate this for me into something simple I can understand ?

Thanks in advance.

Oh I am using darktemplate design .

4 Jun 2011, 8:36 PM
#2
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

You will find the </body> tag in tpl_main_page.php:

includes/templates/your_template/common/tpl_main_page.php

Put it in there :-)

Nick
iszent.com

4 Jun 2011, 8:44 PM
#3
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

niccol:

You will find the </body> tag in tpl_main_page.php:

includes/templates/your_template/common/tpl_main_page.php

Put it in there :-)

I went to that directory and the only two files in there were the

tpl_footer/php & tpl_header.php ??

4 Jun 2011, 9:00 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Adding tracking script to main page

3d4me2:

I went to that directory and the only two files in there were the

tpl_footer/php & tpl_header.php ??

Copy tpl_main_page.php from /includes/templates/template_default/common and make your changes.

4 Jun 2011, 9:08 PM
#5
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

lat9:

Copy tpl_main_page.php from /includes/templates/template_default/common and make your changes.

I did that... main page is now all black - nothing on it.

I deleted the file and site is back to normal. ?

Here is the Url of my site if that helps

http://majikimaje.com/Zhop/

4 Jun 2011, 9:55 PM
#6
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

What lat9 says is correct.

You need to make a override version of that file. ( Or it is better to anyway )

To do that copy the file:

includes/templates/template_default/common/tpl_main_page.php

to

includes/templates/your_template/common/tpl_main_page.php

If this is causing the site to crash then you are doing something wrong. I know that sounds unhelpful but it is true, unfortunately. Or you are altering the file when you are copying it in some way.

Nick
iszent.com

4 Jun 2011, 10:02 PM
#7
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

niccol:

What lat9 says is correct.

You need to make a override version of that file. ( Or it is better to anyway )

To do that copy the file:

includes/templates/template_default/common/tpl_main_page.php

to

includes/templates/your_template/common/tpl_main_page.php

If this is causing the site to crash then you are doing something wrong. I know that sounds unhelpful but it is true, unfortunately. Or you are altering the file when you are copying it in some way.

I will follow your instructions. I merely downloaded the file - made the changes and uploaded it. BUT I renamed the old file so that if I got into trouble I could delete the new file and make the old file name to its normal state.

I will study how to make an over-ride system and I will get back to you when I have more info.

Thanks for having the paitience to help me deal with this issue.

I thought I could do this easily by using the define pages option for the main page; but I see that isn't the case.

4 Jun 2011, 11:01 PM
#8
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

Well, you should be able to do that too. It is better to make an override because you don't mess up the original but editing the origianla should also work.

Which kind of suggests that there is a problem with the code that you are adding. If there is a problem with that code then that will mess up the page too. Because tpl-main_page is one of the first files that actually loads if that file has an error in it you have big problems :-)

I do not know hitsniffer so can't advise there but maybe someone else can.

A lot of people use google analytics for that kind of thing. That does not provide live monitoring but slightly delayed data. But the advantage might be that there are a couple of GA add-on modules for Zen Cart.

I think that the yahoo version of analytics does provide live data.

Nick
iszent.com

5 Jun 2011, 12:18 AM
#9
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

Well I have determined I have major errors with my template.

So therein lies the main problem.

Right now my best bet is to install a different template; create the override system and then go from there.

thanks for taking the time to respond. At least now thanks to all of your advice; I am heading in the right direction.

7 Jun 2011, 6:17 PM
#10
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

this whole simple process required the pasting of the script in the main page under define main pages. It worked first time !! FLAWLESSLY.

Thanks for all the expert help !!

7 Jun 2011, 6:37 PM
#11
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

OK. Great. In general the best advice is to have any javascript as far down the page as possible. But if it works it works.

Nick
iszent.com

7 Jun 2011, 8:17 PM
#12
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

Let me please ask you a question.

I have read and re-read and re-read all about the over-ride system.

TO ME: IT SEEMS all you do. is copy every edited page into your KUSTOM directory(s).??

but in my case; the template being used is not the KUSTOM. It is being run off the base-template I picked.

Maybe I don't have enough files copied into the KUSTOM directories yet ??

Even though in template admin section Kustom is the chosen template.

8 Jun 2011, 7:29 AM
#13
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

Yes you are sort of right.

If your template is 'aardvark' then every file that you edit should go into the 'aardvark' directory. If your template is 'blackmambo'. Then every file you edit should go into the 'blackmambo' directory.

It looks like your template is 'custondark' so all the files that you edit go into the 'customdark' directory.

The name of the template in the admin section is a bit different. A template that is in a directory called 'aardvark' could show up in admin as 'squirrel'. In the template_info.php file for that template you can choose the name of the template in admin. If you have a look at that file you will see what I mean.

So, don't worry about what it is called in admin too much. You need to know which files it is in on the server. In your case this looks like it is a folder called 'customdark'

Nick
iszent.com

8 Jun 2011, 7:32 AM
#14
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

I think that what this means in your case is that the template 'customdark' is being used. But in admin it is called 'KUSTOM'. But I am guessing a bit there.

Nick
iszent.com

9 Jun 2011, 7:10 PM
#15
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

niccol:

I think that what this means in your case is that the template 'customdark' is being used. But in admin it is called 'KUSTOM'. But I am guessing a bit there.

That is exactly right, I have this all messed up and working backwards. I was going to delete everything and just start all over.

but instead, I installed two more stores; so I can learn between them what is going on Zhop Zhopping Zhopped

I will learn and understand much quicker doing it this way with a two redundant backup(s).

I sure have a LOT TO LEARN !! thanks again for taking the time.

11 Jun 2011, 10:28 AM
#16
bigdigits avatar

bigdigits

New Zenner

Join Date:
Jun 2011
Posts:
2
Plugin Contributions:
0

Re: Adding tracking script to main page

Hi, Does this process::adding the code to the main page-- add the code to all pages? I'm almost completing customization of a site and would like to include tracking code on all pages. Thanks

11 Jun 2011, 3:06 PM
#17
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

No!! It only adds the script to the page you put it on.

but... once you have that script on the page; the app will monitor hits on every page in your sites root directory.

I am using Hitsniffer - it is the most awesome stats compliation I have ever seen or used.

11 Jun 2011, 6:27 PM
#18
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

Sorry - but what 3d4me2 says is completely incorrect.

tpl_main_page.php is a template used on every page of Zen Cart. If you put code in that file it will appear on every page in the zen cart installation.

Nick
iszent.com

11 Jun 2011, 7:50 PM
#19
3d4me2 avatar

3d4me2

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Adding tracking script to main page

I didn't put it on that page that you mentioned; When i tried that the store crashed and was completly blank.

I merely put the script in the bottom of the define main page only.

people that hit my store show up on each and every page of the store links they click on.

My apologies for not explaining it correctly !!

11 Jun 2011, 8:22 PM
#20
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Adding tracking script to main page

Hmmm Right, whatever.

Firstly the hitsniffer code is javascript. It cannot magically work on a page on which it is not installed. The script needs to be installed on each page that you want to track.

Here's how that is described in the hitsniffer website :

Input this code under your closing </body> tag, This must be on every page of your site

Fairly evident.

If you want to put the code onto every page of a Zen Cart site then what you do is put it into tpl_main_page. If this is done correctly then it will not crash the page. This is pretty standard stuff and applies to many scripts not just hitsniffer. For instance it is where google analytics is put on many sites. It is a standard technique not only on Zen Cart but also on wordpress, drupal, joomla and lots of other php based sites.

Here's how the hitsniffer website describes that:

If your website have a footer.php , footer.asp , global.footer.php or something like it, you can simply paste tracking code before </body> tag and they will usually show hit sniffer code on all your pages automatically.

While Zen Cart does have a tpl_footer.php file it is better to put it in the tpl_main_page.php file. This ensures that the script is directly under or above the </body> tag and is below the parse times and lower banner on a standard install.

If done correctly this will not cause the site to crash or display a blank page. Most likely if that result is achieved it means that the script has been pasted inaccurately inside <?php ?> tags.

Actually the script will probably work wherever you put it on the page. The 'best practice' is usually to put it as low down in the page as possible. Although we can have a long discussion about the pros and cons of that. Or not -- and just do what the hitsniffer website recommends. (Notice how the advice from hitsniffer is slightly inconsistent about whether it goes above or below </body> )

Nick
iszent.com