Javascript Tracking Code¶
To track content interaction with Harvest, you will have to call the harvest.trackEvent code.
Basic
You will always start with the following basic script:
harvest.trackEvent({
"data": {
"contentInteractionName":"Pageview"
}
});
The script above triggers a content interaction. In this case “Pageview”, but you can use any configured content interaction.
Triggering a funnelstep
Some content interactions can trigger a funnelstep.
harvest.trackEvent({
"data": {
"contentInteractionName":"Newsletter subscription",
"funnelName":"Newsletter subscription",
"funnelStep": "Success",
"isFunnelstep": 1
}
});
The first thing you will notice is the use of the funnelName and funnelStep. These two are required to identify which funnelstep the content interaction is related to.
The isFunnelstep: 1 tells Harvest that it should trigger the funnelstep in stead of being part of it.
Part of a funnelstep
So if we want to track a content interaction that is part of a funnelstep. For example the change on a form field, then we have the following code.
harvest.trackEvent({
"data": {
"contentInteractionName":"Element change",
"funnelName":"Newsletter subscription",
"funnelStep": "Enter details"
}
});
In the above code you will notice that the “isFunnelstep: 1” is removed. This means that the interaction is part of a funnelstep but does not trigger the step.
Tracking user input
Content interaction can be related to page elements or items. In the example above, we only know that in a certain funnel an element change occurred, but we do not know which element or which user characteristic. When tracking user input, we are interested in the “item” user characteristics. We track this as follows:
harvest.trackEvent({
"data": {
"contentInteractionName":"Element change",
"funnelName":"Newsletter subscription",
"funnelStep": "Enter details",
"variableName": "email",
"elementValue": "test@test.nl"
}
});
Notice that you will provide the variableName, which holds the variable that was changed and the elementValue, which holds the value after the change. Harvest will combine these two and output the elementValue as the value of the variable with the name of variableName.
Products
Sometimes a content interaction is related to products, we track these as follows:
harvest.trackEvent({
"data": {
"contentInteractionName":"Product add to cart",
"products": [{
"name": "Strawberry",
"id": "123asd13",
"brand":"EpicFruits",
"variant":"XL",
"price": 5,
"category": "Healthy/Fruit",
"quantity": 5
}]
}
});
You can find all relevant variables in the variables overview of Harvest.
Promotions
A promotion can be tracked as follows:
harvest.trackEvent({
"data": {
"clickType":"Promotion click",
"promotions": [{
"name": "Homepage header",
"id": "XSADSAD",
"creative": "Strawberry promotion",
"position": 1
}]
}
})
Content
All other content will be tracked with the “contents” array as follows:
harvest.trackEvent({
"data": {
"clickType":"Element view",
"contents": [{
"name": "Page section A",
"position": 1
}]
}
})