I don't really get the problem you are having. You already answered your question yourself. Add a mapping(uint => uint) mintGroup
or whatever variable type you need to map the specific tokenId
to the group.
Transfering the token does not change its id and thus will not change the mapping.
You could also add it as a variable in the token itself but handling those is really uncomfortable in comparison to using mapping
.
EDIT: Beware that a token standard like ERC721 is needed to accomplish that. ERC20 standard will not work because every token is the same and therefore cannot store information about the reason of minting it.