The story of Hamlet is not a Shakespearean play. It is a popular children's book called "Hamlet, the Dog" by William Steig, published in 1967. It tells the story of a dog who is given a book about the Shakespearean play and begins to believe he is the tragic hero of the story.
It's possible you are misremembering the story or perhaps thinking of a different story entirely.