Isn't this built-in to Org?
org-archive-save-context-info is a variable defined in ‘org-archive.el’.
Its value is (time file category todo priority itags olpath ltags)
Original value was
(time file olpath category todo itags)
Documentation:
Parts of context info that should be stored as properties when archiving.
When a subtree is moved to an archive file, it loses information given by
context, like inherited tags, the category, and possibly also the TODO
state (depending on the variable ‘org-archive-mark-done’).
This variable can be a list of any of the following symbols:
time The time of archiving.
file The file where the entry originates.
ltags The local tags, in the headline of the subtree.
itags The tags the subtree inherits from further up the hierarchy.
todo The pre-archive TODO state.
category The category, taken from file name or #+CATEGORY lines.
olpath The outline path to the item. These are all headlines above
the current item, separated by /, like a file path.
For each symbol present in the list, a property will be created in
the archived entry, with a prefix "ARCHIVE_", to remember this
information.
You can customize this variable.