This recipe was so useful that we merged it into the Group Discount Codes Add On. When the Add On is activated, a “Group Code” column is added to the CSV export showing the Group Code that was used at checkout (if applicable). The regular Discount Code column will show the main/parent discount code.
You can grab the Group Discount Codes Add On that includes this feature here. If you are interested in how this works to possibly do something similar via custom code, we’ve kept the original code recipe here for reference.