My local classical music radio station has an occasional feature about music from countries other than the usual central European classical tradition. They recently chose two pieces from Chile one of which was Gracias a la vida which had passed me by despite being so famous that it even has its own substantial entry in the English-language Wikipedia (https://en.wikipedia.org/wiki/Gracias_a_la_Vida). It seems to usually be translated as "Thanks to life".
This puzzled me as the preposition a was not what I would have originally chosen followed by an inanimate object. Looking at the entry in the DLE for gracias leads straight to gracia and as far as I can see the only option seems to be gracias a. However looking through previous questions on this site for a possible duplicate I find several examples of gracias por followed by a verb.
So my question is simply what preposition is used after gracias in various circumstances? I am not too worried about finding a translation for the song title as (a) poetry is not obliged to follow the usual rules, (b) I do not want to get side-tracked into the circumstances of the life of its originator Violeta Parra.