This is a thing I have been thinking on and gotten a bit frustrated so I share my thoughts here in hope for clarification.
Let $M$ be a magma, that is a set with an underlying binary operation which we denote $\cdot$. The binary operation is not necessarily associative, that is we do not necessarily have $$a\cdot (b\cdot c)=(a\cdot b)\cdot c$$ Here is the issue at hand, in group theory we can "make" a group abelian by taking the quotient with its commutator subgrouop, $G/[G,G]$, which is abelian, I am wondering if there is something similar for magmas but for associativity.
Of course having dealt with universal algebra, semirings and semigroups (which is the target here in a way) what I need to work with is a relation, more specificly a congruence relation so I figured I would start defining it as such. So I started by saying that $e \mathrel{R} f$, or $(e,f)\in R$, if there exists some $a,b,c\in M$ such that $(a\cdot b)\cdot c = e$ and $a\cdot (b\cdot c) = f$, seemed like a good place to start for me in my quest, only that I realized that there is not necessarily a unit in a magma so we do not have $x \mathrel{R} x$ which is a requirement, well let's just throw those in too then I thought. Which is the reflexive closure of $R$, that is $\text{Cl}_\text{ref}(R)$ from before.
Next I thought about transitivity which is required and I got absolutely nowhere there in my attempts primarily because I could not find anyway to proceed after setting up the equalities with elements and all. I pretty much felt it was impossible so I figured "Let's just do the congruence closure and call it a day" $\text{Cl}_\text{cng}(R)$. Which would of course be a congruence by the very definition but I feel it's a bit "cheap" so to speak. And quite frankly I am not entirely certain that it will yield satisfactory results. So the question is more "is there a way to make a magma associative that is better than this?".
Well, I think the way you do it is correct, but maybe you could describe it in a slightly simpler way. Just consider the semigroup presented by $\langle M \mid \{mn = m \cdot n \mid m, n \in M\}\rangle$ . In other words, take the quotient of the free semigroup on the alphabet $M$ by the relations induced by the multiplication in $M$.
EDIT. Here is an example. Consider the following magma: $$\begin{array}{c|ccc} \ast &a&b&c \\ \hline a & b&b&c \\ b & a&b&c \\ c & c&c&c \end{array}$$ Now form the semigroup with generators $\{a, b, c\}$ and relations $\{aa = b, ab=b, ac=c, ba=a, bb=b, bc=c, ca=c, cb = c, cc=c\}$
Here is the corresponding GAP session: