Track custom event from website

Hi there.
i am trying to send a custom event from javascript on a website, using the information from the developer API Guides — Piwik PRO Analytics Suite 16.35 documentation. but it does not work. see below script.
pageviews and other tracking is working. anyone have some insight ?
i am trying to send this event:

<script type="text/javascript">
     var _paq = _paq || [];
     _paq.push(["trackEvent", "MyCustomEvent", "dataName", "Testing the data"]);
</script>

Hi. The code is correct. It triggered an event on my testing account:

image

Do you see any errors in the browser’s console?

no i see no errors in the browser console.

is there some setup, i need to do before custom events should work ?

Not really. Check what would happen if you type it directly in the browser’s console:

var _paq = _paq || [];
_paq.push(["trackEvent", "MyCustomEvent", "dataName", "Testing the data"]);

If it doesn’t fire, most likely the main Analytics script is not loaded.

thanks.
i have added the custom event to another website were we are using piwik and there the custom event works as expected.
what do you mean excactly with main analytics script ? we can see pageviews etc, would that be possible without the main analytics script ?

Can you check it directly via browser’s console on the affected site? For some reason it doesn’t fire and I’d like to determine why.

ok we changed, some consent settings in analytics setup and now the custom event is working from the console. but it is till not working from the website.

are there any domain restrictions ?
we have multpile domains in one piwik account.

Not really. Can you share the website url where it’s configured?

id rather not post it here as it a public website. do you have private inbox i can mail the url to ?

You can send it via PM here.

Solution: If a custom event code is executed inside a function before loading the container (and effectively the analytics JS library), you have to define it in the global scope via window._paq. Otherwise it’s likely that _paq would be defined just as a local variable.