Yes and no. They can track play time when you launch a game through the Steam client, and they can use DRM to enforce launching games through the Steam client. If you launch one of the few DRM-Free Steam games without using Steam, your play time won’t increase.
GOG also tracks play time if you launch a game via GOG Galaxy. The difference is, every single-player game in their catalog can also be played without GOG Galaxy (and indeed, this is explicitly why I buy games from GOG—I don’t like clients, I just want an executable).
From my (admittedly limited) experience with GOG games and Galaxy, only games downloaded via the GOG website (with 'offline backup game installers') can be launched without Galaxy; games installed with Galaxy will force Galaxy to be running alongside it
Steam is DRM