Imagine a proto-organism, maybe a protein (with no senses). A nearby chemical begins to react and causes it to move or change, maybe like a detergent breaks down surface tension, or maybe by ion exchange. It happens whenever the 2 are in proximity and it turns out to be beneficial to the piece of protein because it prevents it from dissolving or something. After awhile the surviving proteins all contain the proper structure to react that way. Fast forward a few million years; the protein picks up a few more survival traits the same way.
One of the traits is a boolean modifier that optimizes the reaction so that the random chemicals in the environment trigger sensor feedbacks that are "identified" as beneficial (for continued existence) or are bad (dissolution). That identifier boolean is the basis for consciousness but probably not actual consciousness. It compares a number of inputs to define the nature of the external influence. The boolean (if x then z) becomes (if x and y then z) where y is the effect of it's own response. Accumulated booleans develop into a model of the world that includes the proto-organisms own influence. That's consciousness. The boolean modifier is a trait selected by survival of the organism. Mass consciousness is when one group(country/race) modifies it's behavior based on it's relationship to other groups. It is recognition of itself as being part of a broader community/organism.