WiFi shield analogRead issues

I am connecting 4 encoders to an Arduino Mega. I also have a WiFi shield attached to this. The encoders do show exact angle values while I use the Arduino Mega. However, when I use the WiFi shield, the encoder values see random spikes once a while. I am unsure of how to solve this. Any clues as to how to solve it?

Does the problem start as soon as you attach the shield to the Mega, or only after you add code to your sketch to use the shield?

Which shield is it? Please provide a link to where we can get some information about it.

This is the shield I am using. I got this about 2 years ago. It used to work but I am facing this issue, which is new.

https://store.arduino.cc/usa/arduino-wifi-shield

The sequence I tried was:

  1. Try to repeatedly read the analog sensor with just the Arduino m\Mega. There are no spikes and the values are as it should be.

  2. Now I connect the WiFi shield to the Mega and then add the code with the WiFi shield. The intention here is to have the code post the values read through the analog sensor to the cloud. The value is posted as soon as there is a big change in the analog value. So when there are random spikes which are clearly noise and not induced by the environment (I am using an encoder - so what I mean here is it is not physically turned), there is a wrong update to the cloud.

Hope I have been able to better explain the issue.
Thank you so much for your reply @pert