Learning Center
Learning Center Home
Programmable Codes

Audience

This document is designed for people that are already familiar with the concept of System Codes and Dynamic Parameters


What are Programmable Codes?

With Dynamic Codes you can use Dynamic Parameters. Let’s say you want to use the user’s city in your application, then you define a URL like this:
 
http://www.yoursite.com/page.php?city=%(ipcity)
 
On redirection, this will result in
 
http://www.yoursite.com/page.php?city=London
 
if the user is scanning the code in London. That means, the final target URL depends on environment variables.
 
That’s great, but not always sufficient. Sometimes you need more flexibility to build the final target URL.
And that’s exactly what you can do with Programmable Codes. Instead of a URL with Dynamic Parameters you define a Python Expression. Python is a popular programming language. But don’t worry, we will give you many Python templates, so you should be able to create your own Python Expression even if you have no programming skills.
 
 

Hello, World!

The easiest way to start learning about the Programmable Codes is to see a simple example.
 
Let’s say you want to direct an iPhone user to one URL, while directing an Android user to a completely different one, and if it’s neither an iPhone, nor an Android user you want to redirect to a third URL.
 
And here comes the Python Expression:
 
btpy:::    \
’http://www.yoursite.com/forIphoneUsers.html’ if click.userAgent.find('iPhone') > -1      \
else     \
’http://www.yoursite.com/forAndroidUsers.html’ if click.userAgent.find(‘Android’) > -1     \
else     \
’http://www.yoursite.com/otherUsers.html’     \
 
And the result:
If an iPhone user scans your code, the following URL will be called:
 
http://www.yoursite.com/forIphoneUsers.html 
 
Even in this simple example, there are a few things to note:
  • The Python Expression always starts with btpy:::
  • There are 3 objects that contain the Environment Variabels. These are click, redir and the f object (see below: Available Objects). In this example we only use the click object, and read out the device’s user agent by using click.userAgent
  • Standard Python syntax is used.
  • You can perform comparison operators. Here we used > -1
  • You can use conditional expressions. Here we used if and else
  • Use the Backslash "\" if you want to split the Python Expression over multiple lines. IMPORTANT: Nothing is allowed after the backslash, not even a white space character.
 
As you can see, Programmable Codes can be a very powerful tool!
 
Sure, you could set up a web server and program this rule or feature on your own, but it means exactly that, you or your developer will need to write some piece of software and you need to maintain a web server – all ending up in much higher costs.
 
With our Programmable Codes you simply define the Python Expression instead of an URL.
 
That’s it. No developer, no server, no problems.
 
 

Available Objects

Currently, there are 3 objects available:

1) The redir Object

The redir object contains the following properties:

rangeID long The Id of the Code Series
encryptionKey string The Encryption Key
offsetString string The code number of the code series
lastSalt long The current salt value
userID long The anonymous user id
deviceName string The name of the device
screenWidth int The with of the screen
IPLatitude double The latitude based on IP
IPLongitude double The longitude based on IP
IPCountryCode string The two-letter country code
IPCity string The name of the city
 
To access the property deviceName for instance you write redir.deviceName
 
 
2. The click Object

The click object contains properties

platformID int

The Id of the devices platform:

0 = Unknown
1 = Symbian S60 3rd
2 = Symbian S60 2nd
3 = Symbian UIQ3
4 = Symbian UIQ2
5 = J2me
6 = J2me generic
7 = Windows Mobile 5,6,6.5
8 = Palm OS 5.x
9 = Windows Desktop Reader
10 = iPhone
11 = Blackberry Non-Touch
12 = Android
13 = J2me full signed
14 = Symbian S60 5th
15 = Blackberry Touch
16 = Samsung Bada
17 = Windows Phone 7, 7.5
18 = Blackberry OS7
userAgent string The user agent of the device
language string The users' language
ip string The devices IP

To access the property userAgent for instance you write click.userAgent

 

3. The f Object

The f object is a special object that 

BiAdd(BigInteger a, BigInteger b) BigInteger Adds two BigIntegers.
BiSub(BigInteger a, BigInteger b) BigInteger Subtracts two BigIntegers.
Now() DateTime Returns the .net DateTime object (UTC).
Bi(string value) BigInteger Creates a BigInteger from a string.
Prop(string name) string

Used to access Redirect Data. In case of Code Series the Redirect Data of the field name of the currently scanned code is returned. Returns NULL if no Redirect Data is found.

Ue(string value) string URL-encodes a string.
 
To get the amount of days the next month has, for example, you write f.Now().AddMonths(1).DaysInMonth

 

How to create Programmable Codes

Creating a Programmable Code is simple - once you have the Python Expression in place. Just follow these steps:

  1. Sign-in and go to Dashboard -> Dynamic Link -> Basic Mode
  2. Select the code system (QR Code, BeeTagg Code, Datamatrix), enter btpy in the URL textbox and MyProgrammableCode in the Title text box and click the Create button. This will deduct 500 BeeTagg Credits from your Team.
  3. After the code is created, click the “Advanced” tab on the top.
  4. In the URL or Python Macro textbox you copy / paste your Python Expression or use the example below:

    btpy:::     \
    'http://yoursite.com/info/' +   \
    ('workday' if int(f.Now().DayOfWeek) in [1, 2, 3, 4, 5] else 'weekend') +    \
    '.php'

     
  5. As soon as you add btpy::: a Python Expression is recognized and some buttons slide out. Click Sign for Testing.
  6. Now click the Update button.

That’s it.

If you want to use your own Python Expression follow the steps above. Test your own expression and once you are happy with it, click the Sign for Production button, instead of the “Sign for Testing” button. But careful, this will deduct 30,000 BeeTagg Credits from your Team.

 
 

Examples that you can use as templates

 
Example 1: Different URLs on different days
 
btpy:::    \
'http://yoursite.com/info/' + ('workday' if int(f.Now().DayOfWeek) in [1, 2, 3, 4, 5] else 'weekend') + '.php'
 
Explanation:
  1. The Python Expression starts with btpy::: (as always).
  2. To get the current time (time when code is scanned) in UTC you can use f.Now()
  3. So if the day of the week is between 1 and 5, it's a workday, otherwise it's a weekend day.


Result:

  • On workdays the resulting URL is:  http://yoursite.com/info/workday.php
  • On weekend days the resulting URL is: http://yoursite.com/info/weekend.php
 
 
 
Example 2: Different URLs for different devices
 
btpy:::     \
'http://itunes.apple.com/en/app/someapp/id12345?mt=8' if click.userAgent.find('iPhone') > -1
     \
else     \
'https://market.android.com/details?id=com.e241.someapp' if  click.userAgent.find('Android') > -1     \
else     \
'https://www.somesite.com/page.php'
 
Explanation:
​This template can be used if you want to promote a mobile app and want to direct iPhone users to the Apple App Store and Android users to the Android Market. If it's another user, a default mobile website is displayed.
  1. The Python Expression starts with btpy::: (as always).
  2. To get the user agent of a device, use click.userAgent
  3. If the user agent of the device that scans the code contains "iPhone", it's an iPhone. If it contains "Android", it's an Android device and if neither iPhone, nor Android is contained, it's treated as an unknown device.


Result:

  • If it's an iPhone, the resulting URL is:  http://itunes.apple.com/en/app/someapp/id12345?mt=8
  • If it's an Android phone, the resulting URL is: https://market.android.com/details?id=com.e241.someapp
  • If it's another phone, the resulting URL is: https://www.somesite.com/page.php
 
 
 
Example 3: Advanced Code Series with Python Expression
 
btpy:::     \
'http://mysite.com/order.php?productid=' + str(f.BiAdd(10000, f.Bi(redir.offsetString)))
 
Explanation:
This is an advanced example for Code Series. Let's assume you have 50,000 articles in your shop and for each article you have one QR Code.
That means you have a database with 50,000 records.
Unfortunately, the article number which is used as your database's primary key ranges from 10,001 to 60,000.
 
A product's mobile website can be called with the following URL (in this case it's the article with the ID 34655):

http://mysite.com/order.php?productid=34655
 
The problem is, that all Code Series start at offset 1. To match the first code of the Code Series with the first record in your database, you need to add 10000 to the offset value.
  1. The Python Expression starts with btpy::: (as always).
  2. To get the offset of the scanned code you can use redir.offsetString
  3. ​To match it with your databases index, we increase the offset by 10,000. So, the first code of the Code Series returns 10001.


Result:

It the code 24655 of the Code Series is scanned the following URL is called:

http://mysite.com/order.php?productid=34655

and the article with the ID 34655 is displayed. 

 

Cost

The Programmable Codes feature is not free. We charge one-time 30,000 BeeTagg Credits per Python Expression. Each Python Expression needs to be signed (this is an automatic process and takes seconds) before it can be used in productive use. Python Expressions do not expire, nor does the signature. But if you change the Python Expression, you’ll have to re-sign, which will cost another 30,000 BeeTagg Credits.
 
 

FAQ

Are Programmable Codes compatible with all QR Readers?
Yes, it’s a server side feature and therefore not dependent on the reader used. 
 
Can the Programmable Codes feature be used with QR Codes, BeeTagg Codes and Datamatrix?
Yes, you can use Programmable Code with all supported code systems.
 
Can the Custom Hostname feature be used with Programmable Codes?
Yes.
 
Can you use Dynamic Parameters with Programmable Codes?
No. You should use a Python Expression.

 

 

©2005-2017 connvision Ltd - Contact - Privacy - Terms Of Service
German - English - DutchDutch is currently in Beta. Help us to improve! - RussianRussian is currently in Beta. Help us to improve! - TurkishTurkish is currently in Beta. Help us to improve!