InstallationΒΆ
You can use the code below to install Harvest Collect. This will create a global Javascript object harvest.
This code also loads the library that works with data attributes.
<script>
(function (h, a, r, v, e, s, t) {
window.harvest = window.harvest || {};
window.harvest.queue = window.harvest.queue || [];
window.harvest.trackEvent = function (events) {
window.harvest.queue = window.harvest.queue.concat(events);
};
h = document;
a = "script";
r = h.createElement(a);
r.src = "https://cdn.harvest.graindata.com/[account name here]/[environment here]/harvest.js";
r.type = "text/java" + a;
r.async = true;
v = h.getElementsByTagName(a)[0];
v.parentNode.insertBefore(r, v);
harvest.trackEvent({
"event": "pageview",
"data" : {}
});
})();
</script>
Make sure you change [account name here] to your account name and [environment here] for the environment you want to use.
We recommend pasting this code as high as possible in the <head>.
Loading the library is required for both using the Javascript API as well as using data attributes.
For more information read the Javascript API documentation or the data attributes documentation.
Mocking an installation
Harvest checks if an event comes from a website of which the domain is configured. If not, an error will be thrown and no tracking is done. We use this feature to make sure you have configured all domains you want to track.
This might be unhandy if you want to test. To overcome this issue, check out the mock installation documentation.