A blend of programming and seo

Posts from — July 2009

5 must-have google analytics apps

The following is a mix of commercial and free applications that can help you get more out of your google analytics account.

1) Polaris (adobe air app)

Polaris is a cross-platform adobe air app for Google Analytics.

pol 5 must have google analytics apps

Features

  • Cross-platform and easy to setup
  • Dashboard gives you an overview of total visits, pageviews, pages/visit, bounce rate, average time on site, and % of new visitors
  • Switch between different date ranges with using a drag and drop date widget
  • Daily visitor charts
  • Google maps integration (for viewing visitor locations)
  • Reports for viewing the top 25 referring sites
  • Learn which pages perform best
  • The keywords report shows you which keywords are used mostly on organic searches

2) Analytics app (iPhone app)

iphone 1 5 must have google analytics apps

Features

  • Quick Overview Reports for at-a-glance data
  • More Detailed Reports for deeper analysis
  • Supports Multiple Accounts, Multiple Sites, change login anytime
  • Change date range, chart granularity by Day/Week/Month
  • Custom Reports and Goals

3) Ego (iPhone app)

ego 5 must have google analytics apps

Ego gives you one central location to check web statistics that matter to you. With support for Feedburner, Google Analytics, Google PageRank, Mint, Squarespace and Twitter. You can quickly view the number of visits to your website (including daily, hourly and monthly numbers), feed subscription totals and changes, and how many people are following you on Twitter.

4) Youcalc analytics suite (web-based service)

youcalc 5 must have google analytics apps

Features

  • Designed to be run on a variety of platforms (iPhone, igoogle, and embedding in your own apps)
  • Key metrics (visits, page views, conversions, etc.) – see the performance of all your key metrics in one chart
  • Time/day distribution analyzer (Analyze your key metrics distributed by hour of day, day of week or day of month)
  • Dimension analyzer (Analyze your top performing countries, landing pages, campaigns, keywords

5) Enhanced Google Analytics (firefox plugin)

juice 5 must have google analytics apps

This Firefox plugin is designed to allow analysts to get more action out of what changed in the Referring Sites and Keyword Reports. The addon pulls google data for different time-periods, and discovers new and insightful information for the user.

July 27, 2009   No Comments

How to cache smarty templates

What is caching?

Caching is used to speed up a call to display() or fetch() by saving its output to a file. If a cached version of the call is available, that is displayed instead of regenerating the output. Caching can speed things up tremendously, especially templates with longer computation times. Since the output of display() or fetch() is cached, one cache file could conceivably be made up of several template files, config files, etc.

Since templates are dynamic, it is important to be careful what you are caching and for how long. For instance, if you are displaying the front page of your website that does not change its content very often, it might work well to cache this page for an hour or more. On the other hand, if you are displaying a page with a weather map containing new information by the minute, it would not make sense to cache this page.

Setting it up

The first thing to do is enable caching by setting $caching = 1 (or 2).

Example: setting up caching

<?php
$smarty->caching = true;
$smarty->display('index.tpl');
?>

With caching enabled, the function call to display(’index.tpl’) will render the template as usual, but also saves a copy of its output to a file (a cached copy) in the $cache_dir. Upon the next call to display(’index.tpl’), the cached copy will be used instead of rendering the template again.

Technical Note: The files in the $cache_dir are named similar to the template name. Although they end in the “.php” extention, they are not really executable php scripts. Do not edit these files!

Each cached page has a limited lifetime determined by $cache_lifetime. The default value is 3600 seconds, or 1 hour. After that time expires, the cache is regenerated. It is possible to give individual caches their own expiration time by setting $caching = 2. See $cache_lifetime for more details.

example: setting up cache lifetime


$smarty->caching = 2; // lifetime is per cache

// set the cache_lifetime for index.tpl to 5 minutes
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');

// set the cache_lifetime for home.tpl to 1 hour
$smarty->cache_lifetime = 3600;
$smarty->display('home.tpl');

// NOTE: the following $cache_lifetime setting will not work when $caching = 2.
// The cache lifetime for home.tpl has already been set
// to 1 hour, and will no longer respect the value of $cache_lifetime.
// The home.tpl cache will still expire after 1 hour.
$smarty->cache_lifetime = 30; // 30 seconds
$smarty->display('home.tpl');
?>

Caching Tips

Smarty caching can improve performance tremendously, but it doesn’t always work the way that you think it should. In the following situation (which I have seen recently):

example: within (main.tpl) (this is a file named main.tpl)

{if some action}  
        {include file="menu1.tpl"}
       {elseif some other action}
        {include file="menu2.tpl"}
       {/if}

If the main template file (main.tpl) is cached, the includes template files will not get called properly. My solution is to separate the main file into cached and non-cached parts:

(within the PHP file that calls your smarty templates)

//do this on any separate template file that you want cached
$smarty->caching = true;
//the fetch command puts the output of a template file into a variable rather than //the screen
$menu1 = $smarty->fetch('menu1.tpl');
$smarty->assign('menu1',$menu1);
$menu2 = $smarty->fetch('menu2.tpl');
$smarty->assign('menu2',$menu2);

//set the main caching file to false
$smarty->caching = false;
$smarty->display('main.tpl');

(within the new main.tpl)

{if some action}  
        {$menu1}
       {elseif some other action}
        {$menu2}
       {/if}

July 14, 2009   2 Comments

How to migrate from Microsoft access to Mysql

Why use mysql instead of access?

Cost. MySQL is free. Access is not. Mysql can also run on a variety of hardware and operating systems, which does not limit you to proprietary software.

Multiple-user access.
MySQL can handle many simultaneous users. It was designed from the ground up to run in a shared environment that is capable of taking on a large numbers of clients.

Management of large databases. MySQL can manage gigabytes of data, and more. This is possible in access, but not recommended.

Security. When Access tables are stored locally, anyone can run Access, and see your tables. It’s possible to assign a database a password, but many people forget to do this. When your tables are stored in MySQL, the MySQL server manages security. Anyonetrying to access your data must know the proper user
name and password.

Centralized backup location. If individual Access users each store their data locally, backups can be more complicated: 200 users means 200 table backups. While some sites address this problem through the use of network backups, others deal with it by making backups the responsibility of individual machine owners–which usually means no backups at all. Mysql allows you to have one centralized location that can be backed up on a regular basis by a system administrator or DBA.

Manually transferring your data

One way to transfer your data is export all the data from each table (using the file->export command) to a comma delimited text file (CSV). It can then be imported back into mysql using the following commands (from the mysql console client):

mysql> use mydatabase;
mysql> LOAD DATA LOCAL INFILE 'my_access_table.txt'
-> INTO TABLE mytable
-> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
-> LINES TERMINATED BY '\r\n';

you could also use mysqlimport:

mysqlimport --local --fields-terminated-by=,
--fields-enclosed-by='"'
--lines-terminated-by='\r\n'
mydatabase my_access_table.txt

Applications

An application that can make the migration process much easier is called dbTools (free trial available here)

July 13, 2009   1 Comment

Successfully Backing up and Restoring your websites on IIS 6.0

There comes a time in every system administrator’s life when they must face a harsh reality. Your company’s webserver has had a major harddrive failure and it needs to be running again as quickly as possible. I came up with a solution that is fairly simple to execute and is hardware independent.

Disclaimer: I have tried the following and it has worked successfully for me, but use it at your own risk.

Steps for backing up (These steps will be done on the original server)

Step 1: Download and Install the iis 6.0 resource kit (link here)

Step 2: We are first going to backup the metabase files for your server. This is a sort of internal registry designed specifically for IIS.

  • Launch the program called “Metabase Explorer” that came with the resource kit
  • Two items can be seen on the left-hand pane. “Lm” and “Schema”. Both of these need to be saved. To do this, right-click on each one individually and then go to “export to file”. To make it easier for restoring, I prefer to use the exact names of each key: “Lm.mbk” and “Schema.mbk”. If you don’t use this naming convention, just remember the file that is associated with the proper key.
  • Now, the actual websites can be backed up. There is nothing special that needs to be done here. The entire website directory just needs to be copied to your desired location. Also worth noting: remember the exact path of your websites directory. IE: “C:\websites” or “c:\wwwroot”. You will need this when restoring.

Steps for Restoring (These steps will be done on the new/target server)

Step 1: Copy all website files from the backup to the exact filepath as the original server (from step 2 part c from above)
Step 2: install the iis 6.0 resource kit
Step 3: launch the metabase explorer
Step 4: left-click on “LM” on the left-hand pane and go to metabase->import key. Then point it to the LM key file that has been backed up.
Step 5: Follow step 4 for “schema”.
Step 6: This step is important, because without it, your websites will be inaccessible. If this step is forgotton, you will see a username/password authentication box whenever someone tries to visit any of your websites.

  • Open up the IIS manager
  • In the left-hand pane, right-click websites and go to properties.
  • Go to the tab that says “directory security”and under “authentication and access control” click on “edit”.
  • The restore process clears these settings, so make sure “enable anonymous access” is checked and an username/password is set. It will not allow a blank password, so a password will need to be set for the anonymous user account on the system username: IUSER_*MACHINE NAME*. This can be done through the administrative user control panel.

You should now have an exact copy of your websites.

July 10, 2009   No Comments

Using smarty templates

Why use smarty templates?

One of Smartys primary design goals is to facilitate the separation of application code from presentation. Typically, the application code contains the business logic of your application, written and maintained in PHP code. This code is maintained by programmers. The presentation is the way your content is presented to the end user, which is written and maintained in template files. The templates are maintained by template designers.

At its most basic function, the application code collects content, assigns it to the template engine and displays it. The content might be something like the headline, tagline, author and body of a newspaper article. The application code has no concern how this content will be presented in the template. The template designer is responsible for the presentation. They edit the template files, adding markup and bringing it to completion. This typically involves things like HTML tags, cascading style sheets and other tools provided by the template engine.

This paradigm serves several purposes:

1) Designers can’t break application code. They can mess with the templates all they want, but the code stays intact. The code will be tighter, more secure and easier to maintain.

2) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

3) With presentation on its own layer, designers can modify or completely redesign it from scratch, all without intervention from the programmer.

4) Programmers aren’t messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

5) Templates are a close representation of what the final output will be, which is an intuitive approach. Designers don’t care how the content got to the template. If you have extraneous data in the template such as an SQL statement, this opens the risk of breaking application code by accidental deletion or alteration by the designer.

6) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won’t breach security, whether intentional or accidental. They can only do what they are confined to in the templates.

Although application code is separated from presentation, this does not necessarily mean that logic is separated. The application code obviously has logic, but the templates may have logic based on the condition that it is for presentation only. For example, if the designer wants to alternate table row colors or upper-case some assigned content, they can. This is presentation logic, something the programmer should not be concerned with. How often have you had some presentation displayed in a single column and then you wanted it in two or three columns, so the application code needs adjusting to accomodate this? A better approach is to assign the content in one single array and let the template handle the presentation. This will simplify your application and keep your templates flexible. Smarty supplies the tools to handle this kind of situation.

Getting Started with smarty

The first step is to download the smarty template engine Here

1. copy the following to a new file named “smartywrapper.php”

// require the Smarty class
require_once('Smarty.class.php');

// extend the Smarty class
class smartywrapper extends Smarty {

//this will only work with php 5.X
function function __construct() {

// create the Smarty object
$this->Smarty();

// make sure these folders exist and the permissions are set accordingly
$this->template_dir = '/www/example.com/webapp/template/';
$this->compile_dir = '/www/example.com/webapp/compile/';
$this->config_dir = '/www/example.com/webapp/config/';
$this->cache_dir = '/www/example.com/webapp/cache/';
}
}

2. copy the following to a file named “smartytest.php”

// require the new wrapper class we just created from above
require_once('smartywrapper.php');

// create the Smarty_WebApp object
$smarty = new smartywrapper();

// assign a variable, first parameter is the var name, second is the value
$smarty->assign('test_var_1','this is a test');

//display the template file (all html can now be placed here instead of in your php files)
$smarty->display('my_template.tpl');

create a file called my_template.tpl and place it in the directory in $this->template_dir = ‘/www/example.com/webapp/template/’; from above:

This is a test page from smarty, my variable is: {$test_var_1}

launch smartytest.php from your browser and if it is successful, you should see the following

Output

This is a test page from smarty, my variable is: this is a test

Conclusion

Smarty templates can not only be used to increase the overall speed of your php scripts through caching (more about caching can be found Here), but make it easier to develop large-scale applications through the separation of HTML code and php script.

July 9, 2009   2 Comments