1.0.2 • Published 1 year ago

vantevo-analytics-react v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

The analytics of your website, but simpler

Vantevo Analytics is the alternative platform to Google Analytics that respects privacy, because it does not need cookies not compliant with the GDPR. Easy to use, light and can be integrated into any website and back-end.

For more information visit the website vantevo.io.

This package can be integrated into any react framework: next.js, gatsby or other.

Installation

npm install vantevo-analytics-react

Start

...
import VantevoProvider from "vantevo-analytics-react";
...
 
export default function App() {
 ...
 return (
   <VantevoProvider options={{}}>
     ...
  </VantevoProvider>
 );
}

These are the parameters available for the tracker settings, all fields are optional.

OptionTypeDescriptionDefault
excludePatharrayYou can exclude one or more pages, see settings[]
devbooleanThe tracker will not send the data, please check your browser console for more information.false
manualPageviewbooleanAllows you to track page views automatically, the script uses the popstate event to navigate the site.false
outboundLinksbooleanAllows you to monitor all outbound links from your site automatically, the script uses the click andauxclick events.false
hashboolAllows tracking based on URL hash changes.false
domainbooleanUse this option when the script is installed on a different domain than the one on Vantevo Analytics. To use this function remember to authorize the domain to be able to save the statistics, for more information read more.null
trackFilesstringIs a list of extensions, separated by commas, example: zip,mp4,avi,mp3. Whenever a user clicks on a link, the script checks if the file extension is in the list you entered in the parameter and sends a File Download event with the value url.null
saveExtesionFilesbooleanAllows you to save in the event detail together with theurl also the name of the file extension as meta_key to get more information and statistics about your files to download.false
proxyServerstring (Optional)If you want to use a proxy server for requests sent to Vantevo.https://api.vantevo.io/event
proxyServerEcommercestring (Optional)If you want to use a proxy server for requests sent to Vantevo for ecommerce events.https://api.vantevo.io/event-ecommerce

Page view monitoring and event managemenent

Submit a pageview using location.href as the request URL anddocument.title for the page title.

Simple Pageview

...
import useVantevo from "vantevo-analytics-react";
...
 
export default function Page(){
   const { vantevo } = useVantevo();
 
   useEffect(() => {
       vantevo(); 
       /*** or ***/
       vantevo("pageview");
   },[]);
 
   return (...);
}

Pageview change pathname of url

You can send a custom pageview where you can change the page path. In the example below, the page URL is https://example.com/blog?page=2 with the pathname=/blog and the page=2 parameter (the page=2 parameter will be ignored, see the guide, using the pageview event with themeta parameter of type {path:"/blog/page/2"}, the script will save as page path:/blog/page/2.

...
import useVantevo from "vantevo-analytics-react";
...
 
export default function Page(){
   const { vantevo } = useVantevo();
 
   useEffect(() => {
       vantevo("pageview", { path: "/blog/page/2" }, () => {});
   },[]);
 
   return (...);
}

Pageview change title page

Vantevo uses document.title to get the full title of the page, in this example you will see how you can change the page title.

...
import useVantevo from "vantevo-analytics-react";
...

export default function Page(){
  const { vantevo } = useVantevo();

  useEffect(() => {
      vantevo("pageview", { title: "New Title Page" }, () => {});
  },[]);

  return (...);
}
Using "pageview" as the event name, the function will perform a pageview and not an event.

Event

A simple example of how to send an event with the name "Download" and with the information meta_key=pdf andmeta_value=Presentation, the meta parameter is a simple json.

Vantevo Analytics manages the duration of an event (in seconds) using the meta_key=duration, the value of this field is of type Number. With the duration parameter it is possible to send a number (seconds) with the event that will be used to calculate the average duration of the event.

...
import useVantevo from "vantevo-analytics-react";
...
 
export default function Page(){
   const { vantevo } = useVantevo();
 
   useEffect(() => {
       vantevo("Download", { pdf: "Presentation" }, () => {});
       /*** or ***/
       vantevo("video", { title: "Presentation", duration: 30 }, () => {});
   },[]);
 
   return (...);
}

Parametri

OptionTypeDescriptionDefault
eventstring (Optional)Event name.null
metaobject (Optional)An object with custom properties for events.{}
callbackfunction (Optional)A function that is called once the event has been successfully logged.null

Monitoring Ecommerce

In the ecommerce section of Vantevo you can monitor specific actions affecting your ecommerce website and the sources of traffic that lead to sales.

Parameters

OptionTypeDescriptionDefault
eventstring (required)Event Name. See below the list of events you can use for monitoring your ecommerce.pageview
valuesobject (required)An object with custom properties for events.{}
callbackfunction (optional)A function that is called once the event has been successfully logged.null

List events

These are the events to use to monitor your ecommerce:

EventDescription
add_to_wishlista user adds a product to the favorites list
view_itema user views a product
remove_item_carta user removes a product from the cart
add_item_carta user adds product to the cart
start_checkouta user has started the checkout process
checkout_infoa user submits personal data
checkout_shipa user submits shipments data
checkout_paymenta user initiated the payment process
purchasea user has completed a purchase

Example

An example for how to use the trackEcommerce function.

import useVantevo from "vantevo-analytics-react";

export default function Page(){
   const { trackEcommerce } = useVantevo();
 
   useEffect(() => {
        trackEcommerce("view_item", { 
            "items": [
                {
                    'item_id': "SKU_123",
                    'item_name': "Samsung Galaxy",
                    'currency': "EUR",
                    'quantity': 0,
                    'price': 199.99,
                    'discount': 0,
                    'position': 1,
                    'brand': "Samsung",
                    'category_1': "Smartphone",
                    'category_2': "Samsung",
                    'category_3': "Galaxy",
                    'category_4': "",
                    'category_5': "",
                    'variant_1': "Black",
                    'variant_2': "5.5 inch",
                    'variant_3': ""
                }
            ]
        });
   },[]);
 
   return (...);
}

Read our guide for more information of how to use the ecommerce tracking function.

Tracking Files Download

You can use enableTrackFiles() by monitoring file downloads on a specific page using useVantevo().

...
import useVantevo from "vantevo-analytics-react";
...
export default function Page(){
   const { enableTrackFiles } = useVantevo();
 
   useEffect(() => {
       const clearTrackFiles = enableTrackFiles("pdf,zip,mp4,avi", true);
       return () => {
           clearTrackFiles();
       }
   },[]);
 
   return (....);
}

Outbound links

You can use outboundLinks() by monitoring outbound links on a specific page using useVantevo().

...
import useVantevo from "vantevo-analytics-react";
...
export default function Page(){
   const { enableOutboundLinks } = useVantevo();
 
   useEffect(() => {
       const cleanOutboundLinks = enableOutboundLinks();
       return () => {
           cleanOutboundLinks();
       }
   },[]);
 
   return (....);
}

404 - Page Not Found

For the management of the 404 - Page Not Found page we have created a specific event. This function will automatically save a 404 event and thepathname of the page as a value.

You can find the information collected through this function on the Events page.

...
import useVantevo from "vantevo-analytics-react";
...
 
export default function Page(){
   const { vantevo } = useVantevo();
 
   useEffect(() => {
       vantevo("404");
   },[]);
 
   return (...);
}

Vantevo Analytics Guide

To see all the features and settings of Vantevo Analytics we recommend that you read our complete guide here.