Events are not firing in events.js - what can I do to test an event to be sure my events.js is working?

I’m having trouble with
events.js in backend

Working in
Wix Editor, Dev Mode, CMS, etc.

Site link

What I’m trying to do
I am getting no events registered in the console logs from my events.js data. Nothing worked so far. The goal is to register when a priceplan is bought and run code.

What I’ve tried so far
Tried various wix-pricing-plans APIs

Extra context
I need to test somehow if an event is even registered, because even when I am doing a data insert event in any cms collection, I get no logs from events.js. Here is the following example:

events.js:

import wixData from 'wix-data';

export function wixData_onAfterInsert(event) {

console.log('========================================');

console.log('!!!!! WIXDATA INSERT EVENT FIRED !!!!!');

console.log('Timestamp:', new Date().toISOString());

console.log('========================================');

console.log('Collection:', event.collectionName);

console.log('Item:', JSON.stringify(event.item, null, 2));

console.log('========================================');

}

frontend code for the test site when a button is pressed:

import wixData from 'wix-data';




$w.onReady(function () {

// Test-Button (füge einen Button mit ID #testButton hinzu)

$w('#testButton').onClick(() => {

testEvent();

});

});




async function testEvent() {

console.log('🧪 Testing event...');

try {

await wixData.insert('TestEvents', {

message: 'Test event fired at ' + new Date().toISOString()

});

console.log('✅ Test item inserted - check backend logs!');

} catch (error) {

console.error('❌ Error:', error);

}

}

It is very frustrating, because somehow the events.js is never called.

I’m unsure if this is a supported flow but on checking the code and documentation, I only say afterInsert instead of onAfterInsert within the Velo documentation.

I was able to able to get the second half (the frontend code) seems to be working in terms of logging in the front end and the logs.

Hello Rob, thanks for your reply. Yes, the frontend code works for me as well and I get the same results that you get. But there is no console log of the backed coming from events.js for the event that should be firing. In this case inserting something into a cms. And this is my problem.

Any ideas @thomasj? I didn’t see anything in the backend with the code above either but I’ve not really messed with Events.

afterInsert is a data hook, and the code for data hooks needs to be written inside data.js and not events.js

Make sure you read the documentation carefully and use the correct syntax for your code to work as expected.