Data preparation and machine algo for ad click prediction I am an ml noob. I have a task at hand of predicting click probability given user information like city, state, os version, os family, device, browser family browser version, city, etc. I have been recommended to try logit since logit seems to be what MS and Google are using too. I have some questions regarding logistic regression like:
Click and non click is a very very unbalanced class and the simple glm predictions do not look good. How to make the data work through this?
All variables I have are categorical and things like device and city can be numerous. Also the frequency of occurrence of some devices or some cities can be very very low. So how to deal with what I can say is a very random variety of categorical variables?
One of the variables that we get is device id also. This is a very unique feature that can be translated to a user's identity. How to make use of it in logit, or should it be used in a completely different model based on a user identity?
 A: The number of different values in your categorical variables is only important relative to your sample size.  If you only have 10,000 observations, 40,000 dummy variables for each zipcode in the US is probably too much, but if you have 10,000,000 observations 40,000 dummy variables is fine.
You're probably going to have the best results by gathering all the data you can get your hands on and modeling it with a tool like vowpal wabbit that can handle 100's of millions of observations and all of the variables you can throw into it.
As far as the unique identifier goes, if you get more than one observation per user, you probably want to use it in some fashion.  A person who clicked 10 times out of 10 impressions is very likely to click again, regardless of what the other variables are.  A dummy variable for every user is probably not the best approach, but a set of variables like "user's prior impressions", "user's prior clicks" and "user's prior click-through-rate" are probably really valuable.
This trick can also be used to convert your other categorical variables to continuous variables, e.g. "zip code's prior impressions", "zip code's prior clicks", and "zip code's prior click-through-rate."
There's a recently-completed kaggle competition for predicting ad click-through-rates, and there's some great stuff in the forums.  There are also 2 very good blog posts (here and here) on fitting logistic regressions models to this dataset using scikit-learn and vowpal wabbit.
A: 
Click and non click is a very very unbalanced class and the simple glm
  predictions do not look good. How to make the data work through this?

Have a look at here: Does an unbalanced sample matter when doing logistic regression?

So how to deal with what I can say is a very random variety of
  categorical variables?

This is an age-old problem in Stats / Machine learning, called 'the curse of dimensionality'. I can't think of any immediate solutions. I would google and search this website for some valuable gems but at the end of the day the higher the dimensions you want to build a model / train an algorithm on, the more data you need. 

One of the variables that we get is device id also. This is a very
  unique feature that can be translated to a user's identity. How to
  make use of it in logit, or should it be used in a completely
  different model based on a user identity?

As you say, this would be the unique identifier of an observation (user) in your dataset. You should not include this as a predictor variable (unless it has some speific meaning, e.g. id's that are closer to each other tend to behave similarly..)
