Anya's History
Spirit
Soon after the return of magic with the new Seed of Wonder's creation, Anya was revealed to have been haunting Alexander Harris, literally, although when this started is still unclear. Only Xander was able to see her, and they often discussed his past relationship with original Anya and her death, without knowing for certain she wasn’t her actual ghost. Even so, Anya showed resentment and blamed him for renouncing her immortality, leaving her at the altar, and getting her killed; while Xander was able to demonstrate he recognized his guilt and that he was sorry.
Wanting to know if she was real and her presence's purpose, Anya speculated she was meant to help Xander. She was excited with the idea of being a "sidekick," and indeed helped him in various situations, such as breaking his hypnotic state against Dracula and the sirens, encouraging him to communicate with Dawn, and motivating him from an inert state to help Robert Dowling and Rupert Giles. In return, Xander had promised to discover more about Anya's state and how to free her.
Anya and Xander noticed his cats' ability to see her and were able to conclude she was indeed a real entity, rather than just a manifestation his mind. Later, while investigating a case of the psychic Lana Pasternak's demonic possession, said demon remarked that Anya "wasn't invited," and attempted to attack her. Xander saved her and the psychic, before regaining full consciousness, revealed that Anya Jenkins' soul was at rest and the being haunting him was not the real Anya, whether she knew it or not. With the help of his counselor Dr. Mike, he decided to distance from her, prioritizing helping Dawn in another dimension even if Anya wasn't able to go with him. It was then revealed that she was D'Hoffryn creation as a revenge plan against the Scoobies, who he blamed of having "robbing" her from him.
Vengeance demon
Resentful of Xander, Anya was turned into a vengeance demon, and granted Buffy Summers a wish that enabled D'Hoffryn to gain power enough to kill her enemies (the Soul Glutton and the Mistress); but also enough to kill her allies on the second formation of the Magic Council. Made corporeal, Anya then followed D'Hoffryn in an attack against the Scooby Gang, alongside a group of other vengeance demons.
During the battle, Buffy pointed that D'Hoffryn only viewed both "original" and "copy" Anya as possessions: he didn't love neither Anya any more he did Halfrek, having discarded and killed her just to torture Anya herself, and was actually hurt by her independence. Then, at mercy of Anya's attack, Xander said he was sorry for what he did to both Anyas; despite not regretting giving up their wedding neither distancing from her, he recognized he handed the situations badly, abandoning them when they needed him the most.
Anya then turned against D'Hoffryn, granting Buffy a wish to take away the powers she had given him, which was decisive for the Scoobies' victory. The move, though, proved to be her sacrifice, as D'Hoffryn was able to set her on fire. At her final moments, Anya declared that D'Hoffryn made her and only he could end her, but in between she made herself real. She told Xander he was a good man, that she forgave her, and the original Anya would forgive him too. Her ashes were placed inside an urn, kept at the living room of Xander and Spike's apartment, with her name and the inscription: "She owned her life."