Xごとに as “every time X/every X/at intervals of X”
The grammar pattern Xごとに (毎に) is used to express that something happens “every time X happens” or “every X” or “at intervals of X.” Grammatically, Xごとに can be used when X is either a VERB or a NOUN word. If X is a VERB, it must be in its Plain-Dictionary-Form. And if X is a NOUN, it is simply used as is, with the phrasing ごとに following right after without the need of additional particles such as の.
While ごとに is certainly not the only way to express the idea of “every,” it does have a nuance that sets it apart from other similar grammar patterns, such as たびに (度に). In cases wherein ごとに and たびに are for the most part interchangeable, X represents an action done. In cases wherein ごとに is generally used over たびに, X represents a more general time or event, such as a date or a time.
On the otherhand, ごとに can be said to be essentially identical with the usage of the pre-fix まい (毎) before a NOUN-word, X, to mean “every X.” Worth noting is how the kanji for both ごと and まい is 毎.
Konbini ni iku goto ni cola o kaimasu.
(“Every time I go to the convenience store, I buy soda.”)
*same as コンビニに行くたびにコーラを買います。
Gojikan goto ni kusuri wo nomimasu.
(“I drink my medicine every five hours.”)
Jouji Washington wa ichinichi goto ni gyuunyuu wo nomimasu.
(“George Washington drinks milk every day.”)
*same as ジョージワシントンは毎日牛乳を飲みます。