Most Japanese will understand when you say Thank You, but if you use ありがとうがざいました then you win their hearts.
In a shop or other business the assistant will follow this with a bow.
You can say ありがとうございました followed this with a small head nod and people will appreciate your effort.
ありがとうございました is polite to say with everyone.
ありがとう is more informal and is better to use with friends.
Hope this helps you learn a little Japanese and hope to see you in Japan in 2020.