
Scripting is about intelligence. Rather than simply invoking a fixed action, SnapTag's scripts allow you to examine the situation and act accordingly.
You might take in to account;
Scripting is extremely versatile, but here are some examples of the types of things you can do.
Yellow Pages. Place a SnapTag code on your Yellow Pages ad. When people scan it during business hours, ring an 0800 number. If they call outside those hours, bring up a website instead.
Deploying a mobile app. If your business has a mobile applicaiton you'd like to deploy, our codes can take them to the right version of the app for their device. When someone scans the code with an iPhone we send them to iTunes for the install. Androids get sent to Google Play. Other devices can get a mobile site or a message.
Language-based routing. Send English-speaking users to your main site, and Chinese-speaking users to a special translated site.
SnapTag automatically identifies and classes devices for you, and presents that in the Scan.Device property. Unknown devices are classes as System.XTrak.Device.Unknown.
Generally we recommend using a switch statement to group and process responses, however you'd like.
switch (Scan.Device)
{
case Sygnal.XTrak.Device.iPhone:
case Sygnal.XTrak.Device.iPad:
case Sygnal.XTrak.Device.iPod:
case Sygnal.XTrak.Device.Android:
Response.Redirect ("http://m.snaptag.co.nz");
break;
default:
Response.Write (Scan.Device.ToString());
break;
}
SnapTag performs full parsing and scoring on the list of languages the user can accept, and prioritises them accordingly. The best way to evaluate this information is generally to ask SnapTag which of a list of languages is the most appropriate.
To do this, use the Language.DetermineBestMatch call, passing two parameters-
The most efficient way is usually a switch statement. For example, to determine between English (en) and Chinese (zh), you can use;
switch (Scan.Language.DetermineBestMatch ("en,zh","en"))
{
case "zh": // handle if Chinese (zh)
Response.Redirect ( link to Chinese version of website );
break;
default: // handle all other languages
Response.Redirect ( link to English version of website );
break;
}
Scan.Tms returns the scan's date and time, and has various functions for accessing elements of the timestamp.
Scan.Tms.Hour returns the numeric hour of the timestamp, from 0 - 23.
Scan.Tms.Day returns the numeric day of the month, from 1 - 31.
Scan.Tms.DayOfYear returns the numeric day of the year, from 1 - 366.
Scan.Tms.Year returns the numeric year, e.g. 2012.
Scan.Tms.Month returns the numeric month of the year, starting with January as 1.
To retrieve the weekday, use Scan.Tms.DayOfWeek and compare it to these enums;
DayOfWeek.Monday
DayOfWeek.Tuesday
DayOfWeek.Wednesday
DayOfWeek.Thursday
DayOfWeek.Friday
DayOfWeek.Saturday
DayOfWeek.Sunday
SnapTag's Script action uses an ECMA-compliant Javascript type language for its scripting syntax.