2000 Chevy Tracker-Won't Start

I have a 2000 Chevy Tracker and I went to start it one day and it turned over but would not start and 2 of the idot lights were out. I had it towed 1x and it started when it was off the truck. Then it died again. I had it towed a 2nd time. The garage said it was a pcm connection as they got it started by tapping on the pcm. I took it to a dealership and it started for a week and they told me they could not test it to take it home. I took it home and 15 min later it would not start. We eventually got it started and took it back ot the dealer where it has been for 1 month starting fine. How can I resolve this as the dealer said they cannot find the problem if it starts?

You need to call around to different shops, hopefully, some that others have used for intermittent problems. Some are better at this than others.
When a dealer, or a shop, tells you, “We can’t troubleshoot the problem unless the problem is occurring Right Now”, they are lacking in expertise or willingness, or both. Go elsewhere. Hopefully, you can find a willing, able, mechanic. Be sure to remunerate such mechanic fairly.