I'm sorry to hear that your pup Lily is licking everywhere and jerking her head, making coughing/gagging noises.
I understand that she was vomiting earlier.
Is this a new behavior for her or has it just worsened recently?
If this is a new behavior then dogs will often lick and gag when they have a bad taste in their mouth but that should not last long. They can also lick when they have something caught between their teeth, an infected tooth, or something stuck on the roof of their mouth.
Have you looked at her teeth and gums and on the roof of her mouth?
Has her appetite increased or decreased?
Dogs will often lick when they are feeling nauseous or have gastroesophageal reflux to try and settle their stomachs. Since she has been vomiting along with her licking I feel that she may be nauseous.
Metabolic diseases that cause stomach upset like kidney or liver disease, hyperlipidemia, or pancreatitis can cause licking. Anemia can lead to pica or eating or licking non food items. I do recommend that she see her veterinarian for an examination and some blood tests to make sure there are no health problems behind this behavior if her licking/gagging continues.
For now in case this is all related to nausea or reflux to try and settle her stomach you can give her either:
1) Pepcid-ac (famotidine) at a dose of one half of a 10mg tablet per 10 to 20 pounds of body weight every 12 hours.
2) Prilosec (omeprazole) at a dose of one quarter of a 20mg tablet per 10 to 20 pounds of body weight every 24 hours.
Either of these will reduce stomach acid and should help settle her stomach. You can use these for several days if need be or even long term as they are very safe medications.
You do want to mention this behavior to her veterinarian at her next veterinary visit even if she improves with the acid reducers as they will likely want to run some blood tests to look for any possible developing problems.
If this is a new behavior for her it may help to feed her a bland diet as well. A homemade bland diet consists of 1/3 boiled, lean hamburger (or boiled, white, skinless chicken) and 2/3 boiled, white rice or pasta. Give small meals several times a day. Feed the bland diet for several day and if her symptoms seem to resolve then start mixing in her regular diet and slowly convert her back.
If her symptoms return with a return to her regular diet then she needs and examination and some bloodwork and while waiting for results discuss using a low irritant diet like Hills i/d or Purina Veterinary Diets EN with her veterinarian.
Please let me know if you have any further questions.