To use Javascript API you need include main Javascript snippet code before the closing tag of all your pages:
Info
If you already have connected your store with Omnisend - you have already added this snippet.
<script type="text/javascript">
window.omnisend = window.omnisend || [];
omnisend.push(["accountID", "<YOUR_BRAND_ID>"]);
omnisend.push(["track", "$pageViewed"]);
!function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src="https://omnisnippet1.com/inshop/launcher-v2.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}();
</script>
Replace <YOUR_BRAND_ID>
with your brandID
. You can find instructions of how to get brandID
in this support article.
$pageViewed event is used for Live View Website Tracking. If you don't want us to track page views - you can remove omnisend.push(["track", "$pageViewed"]);
from snippet.
Identify contact
The omnisend.identifyContact
JavaScript function provides an optional way to identify customers on your website for more personalized interactions and targeted marketing. This function is particularly useful in scenarios where customers haven't submitted an Omnisend form or clicked on marketing emails. However, it's worth noting that if customers do engage with Omnisend forms or emails, their activities will be automatically tracked even without invoking this function.
Call the function as soon as the customer logs in or provides their contact information.
Syntax:
omnisend.identifyContact({
"email": "<Email Address>",
"phone": "<Phone Number>"
});
- email (optional): The email address of the customer.
- phone (optional): The phone number of the customer. The phone number should be in the E.164 format (e.g. +37061234567).
Note: At least one of the parameters (email or phone) must be provided.
Upon executing this function, Omnisend will initiate tracking of customer activities throughout the website. Events like "viewed page" will be collected automatically.
For tracking additional events like "viewed product", please refer to other guides in our documentation.
onSuccess and onError functions
You can define your own onSuccess
and onError
functions. They will be called after request.
Use callbacks event property:
omnisend.push(["track", "<eventName>",{
propertyName: "propertyValue",
...
callbacks: {
onSuccess: function() {
console.log("ok");
},
onError: function() {
console.log("error!");
}
}]);