The Javascript Smart Marketing Toolkit

This is part of the Javascript Smart Marketing Toolkit.

Local storage (Javascript cookies) tools

Photo of some neatly bundled up cookies

This part of the Smart Marketing Toolkit enables you to save some information on the user's computer and refer to it again later. For example, you can use it to measure what they are most interested in so you can deliver more of that content to them. You can also use it to personalise site content to their interests. Note that:

  • This uses local storage (not cookies) so you can't access this information from your server.
  • Users will be unsettled if you appear to be spying on them, even if you and your server can't see the information. Don't do anything that creeps visitors out!
  • You may need to get opt-in to use this feature, or provide further guidance to users, depending on any regulation that applies where you are.

This feature was originally implemented using Javascript cookies, but was updated in 2019 to use local storage, which is a more robust solution. I've kept the "cookie" name in the code for simplicity and consistency. I've kept the cookies photo, because I like it.

As well as providing routines to store data against a keyword you specify and recall it later using the same keyword, the toolkit provides for several interest counters to be maintained. These interest counters can be used to keep a track of what your visitor is most interested in on your site - which links they follow and which areas of the screen they mouseover. You can use this information to tell them about what's new in the areas they frequent or to try to entice them to sections they rarely visit.

Interactive demonstration

Information is automatically stored when you finish entering it into a form element.

Please enter your name:

What is your best friend's name?

When is their birthday?
(tip: if it's tomorrow, you'll get a special message when the data is recovered)

What is your friend most interested in?

Now click here to see a demonstration of recovering that information from a different web page.

Overview of Javascript local storage routines

Table explaining cookie management functions of the toolkit
function what it does
set_up() The set_up() routine must be run when the page loads.
poke_cookie(name,value) This routine is used to store any value you like in the cookie, together with a name you can use to recall it again. The demonstration files show how this can be used to ask someone's name and store it in the cookie.
peek_cookie(name) This routine is used to recover the information you've stored in the cookie, using the same name as used with poke_cookie().
delete_banner_cookie() This will clear the cookie.


These routines will increase and decrease the counter number given in brackets. The counters must be configured by editing the code in the set_up() routine.
interest_enquire(interestnumber) Returns the current total for the interest number requested in brackets.
most_interested() Reveals the interest with the highest counter level.
least_interested() Reveals the interest with the lowest counter level. Note that if two or more interests have an equal score, the "least interested" or "most interested" one will be the lowest numbered one with that score.

Cycling banner advert

See the page on banner cycling features of the toolkit for more information on what this is doing and how it works.

Navigating the toolkit:


© Sean McManus. All rights reserved.

Visit for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

Coding Compendium

Coding Compendium

A free 100-page ebook collecting my projects and tutorials for Raspberry Pi, micro:bit, Scratch and Python. Simply join my newsletter to download it.

Web Design in Easy Steps

Web Design IES

Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.

100 Top Tips: Microsoft Excel

100 Top Tips: Microsoft Excel

Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.

Scratch Programming in Easy Steps

Scratch Programming IES

This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Newsletter | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About