I recently installed Google Analytics JavaScript on a clients KBPublisher installation and figured someone else may find this useful. In the past it has been recommended to put the Google Analytics JavaScript code into the footer of your web site however Google has now released asynchronous tracking code that can be installed in the header safely. Below is information on the Google Analytics asynchronous JavaScript to be placed in the header of the KBPublisher default template. You can apply the same logic though if you have installed a different template for KBPublisher knowledge base software.
Add Google Analytics Asynchronous JavaScript Code To KBPublisher:
- Google Analytics Profile: First sign into your Google Analytics account and add a new site. Once you login to the Google Analytics site scroll to the bottom of your list of sites and click on Add Website Profile in the bottom left of the center column which will launch the “Create New Website Profile” page as displayed below.
Fill in the correct information in the Create New Website Profile and click the Finish button to show the proper tracking code which can be obtained from the window similar to the below.
- Google Analytics Asynchronous JavaScript: From the page shown in the above image, titled Tracking Code, you will want to obtain the UA-XXXXXXX-X tracking code. Plug that into the asynchronous tracking code listed below.
Google Analytics Asynchronous JavaScript Tracking Code:- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
- _gaq.push(['_trackPageview']);
- (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>
- Create & Configure KBPublisher Template: Now that you have created the site in Google Analytics and obtained the proper asynchronous tracking code login to the server where KBPublisher is being hosted you should generate a new page template within KBPublisher to add the Google Analytics tracking code too. To do this simply copy the page.html file located in the “/kbpublisher-root/client/skin/view_default/default” directory to a new template location such as “/kbpublisher/root/client/skin/template-name/”. So you would not have a new page.html file with a full path of /kbpublisher/root/client/skin/template-name/page.html. Once you have generated this template file login to the KBPublisher admin and configure KBPublisher to use the new page.html template instead of the default page.html by modifying the “Template page to load” configuration setting as displayed in the below example image. To get to this setting you should login to KBPublisher, click Admin Area, click Settings in the top navigation, click Knowledgebase in the Settings sub tabs, scroll to the “Look & Feel (format/template/style):” section, modify the “Template Page To Load” setting with the full path to the template page, and then save your changes.
**NOTE** I initially had written this article explaining to modify the default page.html file. This is not the proper way to do things because when you upgrade KBPublisher your changes will be overwritten during the upgrade this causing you extra work and more than likely causing you headaches. I want to thank user “Evgeny” whom poked me in the comments which prompted me to quickly update the article.
- Add Google Analytics To KBPublisher Template:Now modify the template file we created in step three by locating the HTML “head” and preparing to insert the Google Analytics data before the “HEAD” close tag (). At the bottom of the “HEAD” section of the KBPublisher new template file, also named page.html, add the Google Analytics asynchronous JavaScript we put together in step two that includes the UA-XXXXXXX-X unique site identifier. The new template file we created which is also called page.html file will now look similar to the below.
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>{meta_title}</title>
- <meta http-equiv="content-type" content="text/html; charset={meta_charset}" />
- <meta http-equiv="content-language" content="{meta_content_lang}" />
- <meta name="keywords" content="{meta_keywords}" />
- <meta name="description" content="{meta_description}" />
- <meta name="robots" content="{meta_robots}" />
- <!--[if IE]>
- <link rel="stylesheet" type="text/css" href="{common_ie_css}" />
- <![endif]-->
- <link rel="stylesheet" type="text/css" href="{common_css}" />
- <link rel="stylesheet" type="text/css" href="{common_view_css}" />
- {style_css_links}
- {rss_head_links}
- <script src="{base_href}client/jscript/common.js" type="text/javascript"></script>
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
- _gaq.push(['_trackPageview']);
- (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>
- </head>
- <body>
- {content}
- </body>
- </html>
- Verify Analytics Data Received: Click on a couple pages of the KBPublisher site to send Google Analytics some data. After this log back into Google Analytics and click back through to the Tracking Code page which will display the “Tracking Status” as shown in the below image.
The Tracking Status should state “Waiting For Data: Analytics has been successfully installed and data is being gathered now”.
You should start seeing statistics in the Google Analytics interface in a couple hours.
One advice:
It is better to use “Custom Template” for these purposes.
Instead of changing page.html you should create custom template and add js code to this page.
Then you do not loose your changes in next KBPublisher upgrade.
Please see this article for details
http://www.kbpublisher.com/kb/Change-KBPublisher-Look-and-Feel-(design-integration)_217.html
Hello Evgeny,
Thank you for replying to this. I am bad about following directions when it comes to stuff such as “Templates” however this is definitely the proper way. I am going to update the article to reflect generating and modifying the template so things are not overwritten during an upgrade and all changes lost.
Anyhow I really appreciate you taking the time to reply. It is important when I write such articles that they are proper from the start and if not that they are corrected quickly so people follow the proper directions. Look for the article to be modified in the next 12 hours.
KBPublisher is awesome Knowledgebase software at what I believe to be a very fair price for support and upgrades.
Thanks again.
alex
Thanks for the article. Its suited perfectly for my purposes.
Hello Rafael,
No problem at all. Thanks for taking the time to leave feedback.
Thanks.
alex
hai this is Mr.U.Ramu faculty member of Dr.N.S.Kolla school of business…..,
Hello Ramu,
Thanks for leaving feedback. Not sure your entire comment posted.
Thanks.
alex