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.
This is part of the Javascript Smart Marketing Toolkit.
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 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.
Information is automatically stored when you finish entering it into a form element.
Now click here to see a demonstration of recovering that information from a different web page.
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. |
interest_increase(interestnumber) interest_decrease(interestnumber) |
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. |
See the page on banner cycling features of the toolkit for more information on what this is doing and how it works.
© Sean McManus. All rights reserved.
Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!
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, now in its 7th Edition, shows you how to make effective websites that work on any device.
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.
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.
Code a space adventure game in this Python programming book published by No Starch Press.
Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!