Trigger event from external domain Google Analytics

I have a shop on a third party service. I want to trigger a event when the product gets purchased.

The third party service allows us to add script snippets.

I’m doing this, but I can’t see any custom Events on Reports > Real Time > Events on Google Analytics:

<!-- Global site tag (gtag.js) - Google Analytics --> <script async src=""></script> <script>   window.dataLayer = window.dataLayer || [];   function gtag(){dataLayer.push(arguments);}   gtag('js', new Date());    gtag('config', 'UA-XXXXXXXX-X'); //my ID   gtag('send', 'event', 'demo');    </script> 

Am I missing something? Or is this a restriction that won’t allow us to send events from external domains?

To test this out I’m using and codepen.


I’m trying it from an external domain of my own and it doesn’t register the event either. This time I tried with google analytics instead as this is the exact same code I use on my main domain:

    <script src=""></script>     <script>                  ga('create', 'UA-XXXXXXXX', 'auto');                  ga('send', 'event', 'myTestEvent', 'submit', {             hitCallback: function() {                 // this gets triggered successfully                  console.log("triggered callback!");             }         });     </script> 

Just to clarify, the analytics ID I’m using is the one from my main domain. I would assume using such ID will trigger all events to that account.