It is impossible to understand the Book of Ecclesiastes unless we realise that the author is pretending, until the last two verses, that we are living without consideration of the influence of God in our present and future lives. Thus, when he says in Ecclesiastes 1:14, “I have seen everything that is done under the sun, and behold, all is vanity and a striving after wind”, he is saying that life without God is meaningless.
In Ecclesiastes 3:21 we read
Who knows whether the spirit of man goes upward and the spirit of the beast goes down into the earth?
Presumably the Preacher (i.e., the author) knew that it says in Psalms 49:20, “Man in his pomp yet without understanding is like the beasts that perish”, and in Proverbs 15:24, “The path of life leads upward for the prudent, that he may turn from Sheol (i.e. the grave) beneath”. The first of these verses implies that there is no difference between men and animals and the second is saying that for human beings there is the opportunity to pursue a way of life that raises men above the animals.
In Ecclesiastes 3:21 he asks, on behalf of people who are trying to live without God, “Who knows whether the spirit of man goes upward and the spirit of the beast goes down into the earth?” The Preacher, himself, knew the answer to his question and in the last two verses of the book tells us what it is that gives meaning to life:
“Fear God and keep his commandments, for this is the whole duty of man. For God will bring every deed into judgment with every secret thing, whether good or evil.” (Ecclesiastes 12:13-14)