Steve McKean Web Programming Pages: Introduction to Web Programming - Market research application

MARKET RESEARCH APP

Session 3: Web market research

Introduction

Our next dynamic web application is design and implementation of a hypothetical market research on the web. You will find the visual web pages as illustrations. At the end of the session you will also find a link to the implemented session application example.

Market research

Does the order of links on a page have any influence on the selection by the user? This question has appeared in several connections. One way to approach an answer to this question is to design a web experiment .

Assume that a market research company is trying to measure the public's preference of 2 competing products, A and B . The company designs a web form which has two radio buttons, the upper for product A and the lower for product B , by which the visitor can express his/hers preference for one of the products.

From experience, the market researcher knows that the ordering of A and B on the form may have an effect and that the preference may not be persistent. Two identical forms are therefore designed. One is called the Form 1 and has product A listed first. The other is called the Form 2 and has product B listed first. A script is designed for random selection of the form to be displayed for each visitor. The visitor is asked to request a second form in a week. The second form is another random selection of one of the forms. To attract customers to the web site, a lottery is set up for persons completing the 2 forms.

No names or addresses are required for completing the forms. To participate in the lottery drawing, the participants must, however send in separate forms, called Form 3 , with their names and addresses. A condition for participation in the lottery is that the two forms with preferences were returned.

[top]

Applications outline

Figure 1 is an outline of the system we want to implement. The numbers indicate the flow in the system for each form requested, completed and returned. The challenge will be to find a way to connect the submitted preference forms to the anonymous participant. Further, if a participant is willing unveil his/her name to participate in the lottery, another solution must be developed to check that the person has answered the two required forms.

Implementation

The first step is to establish a subfolder within which we will keep the application. In this folder, the Application.cfm (the capital A is important only if you are working on a web server installed on platforms using Linux or Unix) template must be saved.  Recall that the content of this template is valid for the whole application, i.e. for all templates in the same sub folder. The application template for the market research application looks like the following:

1. <!--- Application.cfm --->

2. <CFAPPLICATION NAME="market_research"

3. SESSIONMANAGEMENT="yes"

4. SESSIONTIMEOUT=#CreateTimeSpan(0,0,30,0)#

5. SETCLIENTCOOKIES="yes">

6. <CFSET session.path="c:\myapplications\market_research">

The application.cfm has 2 tags in addition to the name comment tag. The CFAPPLICATION tag specifies 3 attributes. SESSIONMANAGEMENT permits the use of session variables which have a scope comprising all templates in the applications, but is limited to a session time span. By means of the function CreateTimeSpan(days,hours,minutes,seconds) , the time span for each market research session variables is limited to 30 inactive minutes, i.e. if you leave your computer for 29 minutes it will still remember your session variables.

However, because we ask the visitors to come back in a week, we need a technique for recognizing a client when he submits the second and third form. We have several options. In this application, we use cookies . A cookie is an identification invisible for the user, which the server sends a client when responding to a request, and which the client, if willing, saves in a special file. Next time the client makes a request to the server which issued the cookie, the cookie identifier will be attached to the request, and the server will know from which client the request is sent.

Use of cookies requires that the client has a browser able to receive cookies, and that his browser is set to receive cookies. This technique is useful if the client must be identified over a time period longer than a session. Setting cookies requires the third attribute, SETCLIENTCOOKIES , in the CFAPPLICATION tag. Note that SETCLIENTCOOKIES also influence the persistency of session variables ! Read carefully what RBB writes about Session Variables in Chapter 7.

Finally, Line 6. specifies in a CFSET tag a session variable containing the path to a folder in which we want to store data. If for example you want to save your data in a subfolder market_research within the folder c:\myapplications , the value of session.path in the Application.cfm should be " c:\myapplications\market_research ". You can then in all your templates use #session.path# instead of the longer c:\myapplications\market_research . This is also a very effective technique, if you develop your applications on one computer with a directory structure which differs from that of the the web server on which the application finally should be published.

We recall the rule that the entrance template to an applications should be named index.cfm to prevent unwanted browsing of the folder if the browsing option has not been turned off. In the current applications, index.cfm is an information and menu template ( Figure 2 ):

1. <!--- index.cfm --->

2. <h2><fontcolor="Red">Market research</font></h2>

3. <p>This is a market research to investigate the public's preferences for Product A and Product B. If you respond and complete the requirements stated below, you will be eligible to participate in a lottery.</p.>

4. <p>The requirements are:</p>

5. <ol>

6. <li>Request, complete and submit <a href="prepare.cfm">questionnaire 1</a> today</li>

7. <li>Request, complete and submit <a href="prepare.cfm">questionnaire 2</a> in a week</li>

8. <li>Request, complete and submit <a href="form3.cfm">questionnaire 3</a> after you have submitted questionnaire 2</li>

9. </ol>

10. <p>The 2 first questionnaires require only a single selection and click before you submit the response. The third questionnaire asks you for an e-mail address for notification in case you become a lucky winner in the lottery.<p>

11. <p>The market research sets a cookie in your browser. It is time-limited and will be automatically deleted after 15 days. </p>

As the listing shows, this template could have passed as a HTML file since it contains no CFMX tags. To be consequent, we have given it the extension .cfm . Figure 2 shows the menu.

A random selection between Form 1 and Form 2 is necessary. The template prepare.cfm contains the necessary script:

1. <!--- prepare.cfm --->

2. <CFSET temp=Randomize(Second(now())) >

3. <CFSET selected_number=RandRange(1,2)>

4. <CFIF #selected_number# EQ 1>

5. <CFLOCATION url="form1.cfm">

6. <CFELSE>

7. <CFLOCATION url="form2.cfm">

8. </CFIF>

Each time a pseudo random algorithm is started, it needs a seed . If the seed is the same, the sequence of random numbers will also be the same for all applications. Randomize() in Line 2 is a mathematical CFMX function which instructs the server to plant an initial seed based on the internal server clock . The next function, RandRange(lowest, highest) in Line 3, generates a pseudo-random integer in the range between the lowest and the highest parameter values, in our case either 1 or 2.

Lines 4 to 8 represent an if-else block for selecting the form to present for the visitor. If the logical expression #selected_number# EQ 1 is true, Form 1 is selected by the tag <CFLOCATION url="form1.cfm"> . The CFLOCATION tag is very useful because it redirects the control to another template. If the condition in Line 4 is not true, i.e. #selected_number# EQ 2 , Form 2 is selected for sending to the client.

The form1.cfm and form2.cfm generates the visual pages Figure 3 . The 2 forms are identical except for the ordering of the 2 products and we need consider only form1.cfm.

1. <!--- Form 1 --->

2. <CFIF IsDefined("cookie.user_id") EQ 0>

3. <CFCOOKIE NAME="User_Id" VALUE='#Now()#' EXPIRES="15">

4. </CFIF>

5. <h2><font color="Blue">Preference for products</font></h2>

6. <p>Thank you for visiting this page and expressing your opinion. Complete and submit this form. If this is the first form you submit, please request another form: http://nordbotten.com/courses/cf/information/files/market_research/, and submit it in a week. If you have submitted 2 forms and wish to participate in the lottery, request and submit the form: http://nordbotten.com/courses/cf/information/files/market_research/form3.cfm. </p>

7. <p>Please mark your preference by clicking a button. Comparing the 2 products A and B, I prefer:</p>

8. <CFFORM ACTION="save.cfm">

9. <INPUT TYPE="hidden" NAME="form_type" VALUE="1">

10. Please mark your preference by clicking a button. Comparing the 2 products A and B, I prefer:

11. <p><INPUT TYPE="Radio" NAME="Preference" VALUE="A"> Product A</p>

12.<p> <INPUT TYPE="Radio" NAME="Preference" VALUE="B"> Product B</p>

13.<p> <INPUT TYPE="submit" name="SUBMIT" VALUE="Submit"></p>

14. </CFFORM>

The form templates start with an CFIF tag in Line 2 which tests if a variable called cookie.user_id has been defined. The function IsDefined("cookie.user_id") returns value 1 if true and 0 if false. The first time a client requests one of the 2 form templates, we know the function must return a 0, while in later requests from the same client, the function will return 1 because the request now also includes the hidden cookie. If the function returns value 0, the variable User_Id is defined in Line 3 by the CFCOOKIE tag. The variable is assigned a unique value obtained by using the clock function Now() . We also require that the cookie will expire in 15 days. Using cookies, we are able to connect 2 or more responses from a client without requesting any further identification. CFORM has some additional features compared with the HTML FORM .

After some informative text in Lines 5, 6 and 7, the CFFORM tag follows specifying the subsequent action by template save.cfm . Two radio buttons are included in the form for the visitor to flag his/her product preference. The form end with a submit button. One of the 2 radio buttons must be pressed. Note that we do not ask the visitor for his/her name for anonymity reasons.

When the completed form is submitted, template save.cfm is executed. The Line 2 test if the file to which the data should be written has been established with a heading, and if not, it is established by a CFFILE tag with attribute ACTION="write" in Line 3.

It saves the returned response identified with the cookie user_id , the form_type and the preference in a text file named response.txt . In Line 5, the template makes use of a CFFILE tag which can have several actions and attributes. In this application we use the action "append" which require 2 attributes, FILE in which the data from the form should be saved, and OUTPUT , the variable values to be saved. Note that the complete path for the file is required. , and we make use of the value of the session variable set in Application.cfm .

1. <!--- save.cfm --->

2. <cfif IsDefined("reponse.txt")EQ 0>

3. <cffile action="WRITE" file="response.txt" output="Response text file">

4. </cfif>

5. <CFFILE ACTION="append" FILE="#session.path#\response.txt" OUTPUT="User id: #cookie.user_id#, Form_type: #form.form_type#, Preference:#form.preference#>

6. </CFFILE>

7. <CFLOCATION URL="index.cfm">

The last 2 building bricks of the market research application are a form requesting the email address if participation in the lottery is wanted ( Figure 4 ), and a template for saving address:

Since we already know the user identification of the participant, the form can be quite simple:

1. <!--- Form 3 --->

2. <p>Thank you for visiting this page and expressing your opinion. If you have complete and submit 2 form with your preferences for Product A and Product B, you are eligible to participate in the lottery. </p>

3. <CFFORM ACTION="save2.cfm">

4. <p>Your name:<cfinput type="Text" name="name" required="yes"></p>

5. <p>e-mail address:<cfinput type="Text" name="email" required="yes">></p>

6. <p><INPUT TYPE="submit" name="SUBMIT" VALUE="Submit">></p>

7. <p></CFFORM>></p>

The cookie identification will be attached also to this form when returned, and we can check that the visitor is eligible as participant in the lottery.

The save2.cfm template takes care of saving the cookie user identification of the visitor, his/her name and address in address.txt . As for the first text file, the template tests for the existence of the file, and establish the file if necessary:

1. <!--- save2.cfm --->

2. <cfif IsDefined("address.txt")EQ 0>

3. <cffile action="WRITE" file="address.txt" output="Address text file">

4. </cfif>

5. <CFFILE ACTION="append" FILE="c:#session.path#\address.txt" OUTPUT="User id: #cookie.user_id#, Name: #form.name#, Email address:#form.email#>

6. </CFFILE>

7. <CFLOCATION URL="index.cfm">

By sorting and merging saved responses in response.txt and address.txt, we can establish a list of names and addresses for all visitors which have returned 2 forms with preferences, and the form with their e-mail addresses. The lottery can easily be carried out.

For market research analysis, the file response.txt will give give 2 main classes of data: First, all responses can be used to analyze the overall preferences for Product A and B. Second, all responses sorted by Form 1 and 2, can be used to analyze the effect of the ordering, and third, the responses ordered by user identification and time received can be used for investigating the preference persistence over time.

The template report.cfm gives an unedited display of the response.txt file. It can easily be copied and processed by EXCEL.

1. <!--- report.cfm --->

2. <cffile action="READ" variable="report" file="c:#session.path#\response.txt"></cffile>

3.<cfoutput>#report#</cfoutput>

Inspect the values of the cookies, which indicate that some visitors have been visiting several times. You can also see the content of address.txt from the menu page by means of a similar template, report2.cfm .

Exercises

a. Read Chapter 3 in RBB about ways to pass data between templates. In the first part of Chapter 7, you can read about application templates and cookies, and jumping to Chapter 12 , you will be able to read more in detail about the CFFILE tag.

b. Study the application Market research carefully. In the first form, it is possible to request either questionnaire 1 , questionnaire 2 or questionnaire 3 . It would be more professional that only questionnaire 1 could be called if this was the first visit, only questionnaire 2 if the first had already been submitted, and only questionnaire 3 if both the previous questionnaires had been completed. Try if you can see a way do this improvement.

c. Copy and install the templates on your own computer and try to run the application. You may meet a few problems, but don't give up.

d. Extend the assortment to 3 competing products. How would you re-arrange the experiment to obtain an unbiased set of preference responses?

[top]

Link to the session example.

Link to the session test.

 

 

POP UP IMAGES

 

[top]

 

Other information:

 

 

 

 

 

 

 


[top]

Market Research Application

HOME- INDEX - HTM
oreilly EX. 3 -10
OREILLY EX. 11 - 17
OREILLY EX. 18 - 28
OREILLY PAGE INDEX
WACK
WACK EX. 1 - 14
WACK EX. 15 - 25
WACK EX. 26 - 36
WACK PAGE INDEX

 

ADOBE - COLDFUSION TAG REFERENCE
FUNCTION REFERENCE
 
MACROMEDIA LIVEDOCS
 
macromedia help

 

Course Project

MY LINKS- RESOURCES

Steve McKean
UH-Email

CT LOGIN

CT FORUM CF
user - enter

MACROMEDIA FORUM
user - enter

Course Project MY LINKS- RESOURCES Steve McKean UH-Email
 
ADOBE - COLDFUSION TAG REFERENCE
FUNCTION REFERENCE
 
42773
7

 

Course Project

MY LINKS- RESOURCES

Steve McKean
UH-Email

CT LOGIN

CT FORUM CF
user - enter

MACROMEDIA FORUM user - enter

 
TWW

O'Reilly Book Site

Read Me

 

CFMX HISTORY RESOURCES
OBJECTIVES

1.-Introduction to web programming
2. Implementation tool: CFML

Application
Examples

3.- Market research application
4.- Using databases
5.- Online experiments
6.- Search engines
7.-e-learning
8.- e-shops
9.- Agents

Implementation aspects:

10.-Data exchange
11. -Regular expressions
12. -Re-using code
13. -Distributed processing
14 .- CF components
15. -Web services

Course project