In the first example she was either attracted to you or being dared to touch your butt, for whatever reason by the other guy.
Either way, it is an invitation. Instead of ignoring it you should've went with:
You: "*Grabs her butt back* are we playing tag?

"
or
You: "Hey! I usually charge $5 dollars for that. Pay up. I'll take cash, or a drink."
then escalated, specifically befriended other guy and/or isolated from other guy.
In the second example you should have ejected from the set with a suggestion of a #close, at least...You were forced to leave because of your friend, and generally when you're leaving that results in a do or die attitude from both the pua and the subject.