Getting data from an item before it's used?

Sooo basically my problem is that I'm trying to make a custom totems library. I need to detect the custom data of the totem, but they only way I can think of doing that without using ticking commands is to detect that the player used the totem with an advancement, and then get the custom data of the totem. I don't think this would work though because the totem would already be gone by time I try to get its custom data. Is there a way to do this without just having a ticking command storing the data somewhere?

Continue to help post