Here’s a nice overview that will definitely help point you in the right direction, although some of your required functionality won’t be possible until we release device tag context variable, which comes in just a couple of weeks.