The code snippet is showing you how you can access the tooltip information on mouseover.
You should be able to just copy that code block into your addon file and whenever you mouseover it should allow you to access that spell's spellID and then do what you need to do within that code block.
Lua Code:
GameTooltip:HookScript("OnTooltipSetSpell", function(self)
local name, id = self:GetSpell()
if id then
-- Work with the spell ID you now have access to
end
end)