Try to raid that gym once a week. That should be enough to put your name in the lottery in case the gym host an Ex raid. Niantic says that higher gym badge also increase the chance, so if you are in a position to get gold badge on that gym it might help (but not necessary).
Triggering an Ex raid on a specific gym is a community effort and not an individual one. Factors that are speculated to affect it is the number of unique accounts raiding on the gym, and number of trainers on a single raid. search for EX-raid triggering on reddit for more information.
What do to for EX passes?
Theres a gym near by (and by nearby I mean 5 miles) and its known for giving out EX passes, and apparently today and tomorrow are the best chances to get them. I know to get an EX pass you need to win a raid at that gym, but I'm wonder what actually triggers the giving of the pass or is it just random chance?
I already know what the mewtwo counters are, ive had them prepped since before the tyranitar event
Answers
It wasn't rigorously proven, the best study I saw of this is pretty old and some things have changed to the better since. Here is the link:
https://www.reddit.com/r/TheSilphRoad/comments/7s7ae7/who_gets_selected_for_ex_raids_a_statistical/
Anecdotally, I only focus on 1 Ex gym and raid it once a week, I have never missed an EX pass for that gym.
Giving you the pass is pretty much Random Chance - but in my experience, it seems to be based on particular raids, not simply on individuals. For example:
Day 1: 1 person does a Magikarp Raid. (1)
Day 2: 10 people do a Regice raid. (2)
Day 3: 3 people do an Absol Raid. (3)
Day 3: 8 people do a Tyranitar raid. (4)
Day 4: 11 people do a Regice raid. (5)
Day 4: 1 person does a Machamp raid. (6)
Day 5: 6 people do a Golem raid. (7)
Day 6: 4 people do a Jolteon Raid. (8)
Day 7: EX Raids invites go out, and people who did (8), (6), (2) and (1) get EX Invites. People who ONLY did (7), (5), (4) or (3) don't get an invite.
I don't know if that is definitely how it works, but in my experience when I get an EX Raid invite, I get to the EX Raid and see most of the people from a particular raid. My last EX Raid (which I couldn't go to) was the same way - about 20 of us rushed to get the raid done before Noon because we knew EX Raids were about to go out that day. And sure enough, 2 hours later I got an Invite to an EX Raid on that gym. It was the first time I had been to the gym - I didn't even know where the Gym was until someone put up a Google Map marker for many of us. Because my bag was full at the time, I couldn't even spin the gym. I did one raid there, and 2 hours later I had an EX Raid invite to that gym. As did everyone else who was at the same raid - even those who did it in private groups.
Sadly, the EX raid was at 10:30am on a Wednesday, so only about 5 of the 20 of us could make it. Lots of angry Trainers around my area that week.
Regardless of what others have said, I think it's as simple as it being a sponsored gym and the volume of visitors. For example, at the Mall of America, a real high traffic place, at one of the Sprint gyms, I'm getting an EX pass every time, even for level 1 raids. My son's account has only done 28 total raids but has gotten 3 passes. However, at a gym around here, at a park I take the kids, I got my first EX raid pass and I have done more raids at that gym than any other.