Ambien is for sleeping, it gets its name from AM (morning) + bien (spanish for good), so GoodMorning. Random fact.
If you want to wake up to a good morning however, you'll learn to address the underlying conditions inducing your insomnia to begin with, benzodiazepine therapy is not very effective for most people especially the longer you take it, so it's best to not take the ambien, IME it just is a super strange hallucinogen.
If you must, you will take the ambien immediately before getting in bed and you won't take the pill expecting it to suddenly be potent enough to knock you out and that "you'll go to bed when the pill makes you tired" because then it never has a chance as a hypnotic, weak already as it is, and it's ridden with hallucinogenic side effects and it is very scary talking to someone who's blacked out on zolpidem, it's usually freakier than talking to someone who's tweaking or someone who just smoked an 8th of crack....
My $0.02, I fucking hate z-drugs they really are useless and their risks outweigh the benefits in 90% of the cases I see, and people are better off finding other ways to cope with insomnia. Even if that means some chemical assistance with more traditional/classic benzodiazepines for a while, long-term benzo use for sleep is a hopeless, miserable, lonely, long road that you don't want to start hitch hiking down... It often starts with Zolpidem because it's been marketed so heavily and most general practitioners I've known like to start people on it before moving onto the more hardcore benzos.