Hail vulgar juice of never-fading pine!
Cheap as thou art, thy virtues are divine.
To shew them and explain (such is thy store)
There needs much modern and much ancient lore.
Here the poem opens by noting the occasion: the phenomenon of tar-water's apparent healing virtues, and, more generally, its hidden complexity. This will be a theme throughout the poem: there is more to tar than meets the eye, and if you inquire into this apparently lowly substance in the right way, you will find yourself drawn into much greater things.
While with slow pains we search the healing spell,
Those sparks of life, that in thy balsam dwell,
From lowest earth by gentle steps we rise
Through air, fire, æther to the highest skies.
Things gross and low present truth's sacred clue.
Sense, fancy, reason, intellect pursue
Her winding mazes, and by Nature's laws
From plain effects trace out the mystic cause,
And principles explore, though wrapt in shades,
That spring of life which the great world pervades,
The spirit that moves, the Intellect that guides,
Th' eternal One that o'er the Whole presides.
Note that we investigate the healing properties of tar "with slow pains." This emphasis on the difficulty of the investigation carries over from the first part of the poem, and continues until the end. By "sparks of life" Berkeley means pure invisible fire (=light=aether), which he hypothesizes to be the source of tar-water's efficacy as a medicine. He then opens the ascent them that continues through the rest of the poem. From lowest earth (tar) we proceed to air (from which plants distill their sap, which becomes tar), to fire or light (which is what they draw from the air), to aether (which is fire or light in its purest form, pervading the universe and guiding the motions of everything else), to "the highest skies," i.e. Heavenly providence. "Clue" can mean either 'clue' or 'thread'; it does double-duty here. The link between threads (the original meaning of the word) and what we call clues can be seen in the story of Ariadne, to which the poem alludes. The world is a maze, but by seeking the true explanation of the phenomenon, we can follow a thread that leads out of the maze, or, in other words, by discerning Nature's laws we can move from the phenomena or "plain effects" to the true causes of the effect, and, in particular, to God. Notice that there are actually two ascents here. There is an ascent from effects to causes in things (tar, air, fire, aether, God), and there is an ascent in the type of inquiry (the data of the senses, the patterns of sensory data, the rational investigation of what underlies those patters, the intellectual understanding of the phenomena in relation to its true causes). "Fancy" is another word for imagination, and means (roughly) sub-rational sensory processing.
Go learn'd mechanic, stare with stupid eyes,
Attribute to all figure, weight and size;
Nor look behind the moving scene to see
What gives each wondrous form its energy.
Vain images possess the sensual mind,
To real agents and true causes blind.
The "mechanic" here is someone attempting to explain the efficacy of tar entirely in terms of the motion of particles. This is staring "with stupid eyes" - if you've ever seen someone so tired they can't think very quickly, you've seen the sort of staring with stupid eyes (stupid from the stupor of sleep) Berkeley means. The stupor of the mechanical philosopher is that he can't get beyond the appearances to the true causes, which are not sensible and therefore not, strictly speaking, imaginable. The mechanical philosophers, caught up with the success of mechanistic philosopher, avoids the real rational and intellectual work required to see what is really happening. Berkeley holds that the only real agents and true causes are minds or spirits; this is the basis for one of his arguments for God's existence.
But soon as intellect's bright sun displays
O'er the benighted orb his fulgent rays,
Delusive phantoms fly before the light,
Nature and truth lie open at the sight:
Causes connect with effects supply
A golden chain, whose radiant links on high
Fix'd to the sovereign throne from thence depend
And reach e'en down to tar the nether end.
Contrasted with merely mechanistic investigation is genuinely intellectual study of the world. This includes mechanistic investigation as part of the ascent; but in the right sort of inquiry we attempt to go beyond bare appearances, and beyond the purely mathematical patterns exemplified by those appearances, to causes. When we do this, and rise, through reasoning, from a purely imaginative level of inquiry to a genuinely intellectual level of inquiry, false views start falling away and we begin to understand the true nature of the world. Notice that the golden chain discovered by the intellect is fixed to "the sovereign throne," not tar. We ascend from tar to God in inquiry, but this is only possible because there is a chain of cause and effect leading from God (as first cause) to tar (which, because of its utter mundaneness, symbolizes the least effect). By recognizing effects, we begin to inquire into causes; and even if we start with phenomena as unimpressive as those associated with tar, we reach God.
The poem, then, is an account of what Berkeley thinks is the correct attitude in investigating anything. 1) Start with the phenomena; 2) recognize that it takes time and effort because there is more even to the least important things than meets the eye; 3) rise, from effect to cause, through the causal chain by, at the same time, rising from the senses, through the imagination, through reason, to intellectual understanding; 4) we understand things, properly speaking, by understanding how they fit into the golden chain that is the universe, and which depends on God.