Skip to content
GitLab
  • Explore
  • Sign in
  • Davide Ciacco
  • Web Analytics Web Lib Example
  • Wiki
  • Home
  • Events
  • Events configuration
  • Send Event Method

Send Event Method · Changes

Page history
Update home/events/events configuration/Send Event Method authored Apr 25, 2021 by Davide Ciacco's avatar Davide Ciacco
Hide whitespace changes
Inline Side-by-side
home/events/events-configuration/Send-Event-Method.md 0 → 100644
View page @ ec8d9b23
The current instance of `WebAnalytics` is stored inside `window._waInstance`.
WebAnalytics has a method called `sendEvent`:
```typescript
sendEvent(eventId: string, dataObject?: { [key: string]: string | number });
```
It can be called from anywhere the `WebAnalytics` instance can be reached, the `eventId` parameter is required.
In this example two events are defined, one triggered when a button identified with the css selector `'#primaryButton'` is clicked and its text content will be sent with it, the second one will be sent when the mouse pointer position will be at least 500px lower than the top of the page once, with the `dataObject` containing its horizontal position:
```js
(function() {
const webAnalytics = window._waInstance;
if (webAnalytics) {
// send event when primaryButton is clicked
const primaryButton = document.querySelector('#primaryButton');
primaryButton.onclick = (e) => {
webAnalytics.sendEvent('CUSTOM_EVENT_CLICK', { buttonText: e.target.textContent });
};
// send event when the mouse vertical position exceedes 500px (once)
var exceeded = false;
document.onmousemove = e => {
if (!exceeded && e.pageY > 500) {
exceeded = true;
webAnalytics.sendEvent('CUSTOM_EVENT_EXCEEDED_Y_500PX', { posX: e.pageX });
}
};
}
})();
```
\ No newline at end of file
Clone repository
  • home
    • events
      • events configuration
        • Events Configuration File
        • Send Event Method