(Okay, technically a song is a pattern. But it's a really nice one.)
Seriously though, you can think of melody and etc as relative parts of a scale as well as intervals between notes. Ear training using scales is simplest and eventually starts to apply to more complicated patterns. Eventually you recognize the intervals and scales even if you are not consciously thinking about the descriptors like 'oh this is a major third interval'
First you familiarize yourself with an interval, by just playing it all over your instrument, listening and singing it.
Then you test your recall: Play a note N, and try to sing N+I (where I is the interval).
Once you know more than one interval, you can also test recognition: Someone else plays an interval (N,N+I) and you try to identify I.
Once you've got the twelve intervals (you can go past the octave but that's pretty easy so basically there are only 12 to learn) you can do similarly for chords. Chords are also easy compared to intervals, though, because they are built up from intervals, so even before you can recognize them all at once, you'll already have the ability to pick them apart note by note to figure out what they are.
If you want to learn improvisation it helps to also investigate "why" - why this particular rhythmic figure (e.g as shown in the OP article), why this chord voicing (e.g. block chords? Quartal harmony? Drop-2?), why this melody (e.g. ascending or descending? Arpeggiating the chords or "playing outside"?) etc etc
Edit: One more thing: it's OK to improvise with the help of something like iReal Pro, but nothing replaces improvising with real humans, find a group of like minded people that would like to play with you
As an aside, music skill (and many other skills) can be divided into Reading and Writing. Reading consists of either actually reading sheet music, or Playing by Ear. Writing is executing what is in your mind. In the context of improvisation, it's coming up with those things to execute in the first place.
To be honest, I am a good Reader, but a poor Writer myself, and still in the beginning of this part of my journey. I love listening to jazz, and playing along, but devising my own melodies is almost beyond the current me. But what's great about music is that every day you practice is one that you get better.
Take the song, load it up in transcribe (https://www.seventhstring.com/) or similar software, pick a part. Up to here, this method and yours is the same. But rather than try to worry about the exact notes being played, study the context by just singing and playing over the song and seeing what works and what does not.
There's just a lot more information than just the notes that were played. So this type of transcription gets you to navigate the same context the musicians were playing in. And as you do it, you'll start hitting the actual notes, and eventually you can close in on them. What's great is that it's fun, playful, musical, and you can do it even with songs that are way out of your level when transcribing note by note or learning from a score.
Using a human language analogy, your suggestion would be to mimic conversations and mine would be to babble in other people's conversations until you become fluent. It's clear in human languages that one is much faster than the other. Sure babies are geared for it, but I think the babbling would work for adults too if they became cute as a baby or puppy, got over themselves, and could shamelessly babble onto other's conversations.
The best book on the matter I've read of how to learn by ear is "The Gift of Music" by Victor Wooten. It's kind of weird in that it's written as a fiction book, but there are definitely music lessons. And if some of them feel too out there, just listen to him play. He's a master, not a stoner pretender.
There's also "Thinking in Jazz", but I am only a fourth or third of the way and so far it's mostly about the historical and cultural background of improvisers. It's not gotten too into the weeds musically speaking.
Do you confirm the name? I cannot find any reference to it. We do have 'The Music Lesson' and 'The Spirit of Music'.
The spirit of music is supposed to be the sequel but I haven't read it yet.
Start by listening to music you like, then pick an instrument. Copy what they did, note by note, but 100x slower. It may not be fun at first, but you will pick up speed slowly, and soon, you're making music, and maybe you'll learn something along the way.