yes, you can connect it.
2 W = 33 dBm, after 50 dB attenuator it will be 33 - 50 = -17 dBm, it should be safe for spectrum analyzer.
Before connect I suggest you to check if your attenuator works properly.
And note! These Chinese attenuators have just one side which is intended to apply high power. If you connect transmitter to the wrong side, your attenuator will burn out.
This is not trivial to understand which side is intended for high power. I found that Chinese manufacturers probably marking it with a small "SU" marking on connector, but this is not 100% information, just my finding. I burned out several attenuators in such way, because these attenuators don't have any instruction or manual or any kind of note about where is input and where is output and there is even no any mention that they are single way. And the worse thing is that sellers also don't know it So it's just your luck to find where is proper input
I think that your attenuator probably has high power input on the bottom connector (see first photo on the product description). Check if it has "SU" mark. If it is present, then this connector probably high power. But I cannot guarantee...
May be someone can suggest more reliable way to check which connector is intended for high power input.
I dunno about Chinese stuff, but the normal convention with smaller attenuators is that the input to the attenuator is a female "N" connector, & the output a captive male "N", to make it easier to connect directly to a following test instrument.
Although the one linked to is getting a bit close to the size where it could damage the SA's input front panel connectors due to its mass & mechanical advantage, I'm pretty certain it would follow that convention.
Similar units from the USA, the UK, Japan, & Germany commonly have an arrow silkscreened onto the body, showing the signal path through the device, as do many of the large "thruline loads".
Higher power "thrulines" & the like, often have female "N" connectors on both ends--- maybe to stop morons hanging them off the front of SAs, but more probably, so they don't need to use an adaptor to connect to a standard cable.
At 2 watts it is doubtful that it would make much difference if the OP got the attenuator input & output mixed up.