Is it possible to track 3rd party analytics? [Clevertap]

I see that I can add custom code to the body. I’m adding some Clevertap code to track analytics:

<script type="text/javascript">var clevertap = {event:[], profile:[], account:[], onUserLogin:[], notifications:[], privacy:[]};
 // replace with the CLEVERTAP_ACCOUNT_ID with the actual ACCOUNT ID value from your Dashboard -> Settings pageclevertap.account.push({"id": "CLEVERTAP_ACCOUNT_ID"});
clevertap.privacy.push({optOut: false}); //set the flag to true, if the user of the device opts out of sharing their dataclevertap.privacy.push({useIP: false}); //set the flag to true, if the user agrees to share their IP data
 (function () {
		 var wzrk = document.createElement('script');
		 wzrk.type = 'text/javascript';
		 wzrk.async = true;
		 wzrk.src = ('https:' == document.location.protocol ? 'https://d2r1yp2w7bby2u.  cloudfront. net' : 'http://static. clevertap. com') + '/js/a.js';
		 var s = document.getElementsByTagName('script')[0];
		 s.parentNode.insertBefore(wzrk, s);
  })();
</script>

following the instructions here support wix. com/en/article/embedding-custom-code-to-your-site#working-with-third-party-code, I can add this code to my HEAD and see that it runs.

Now I want to track user events, which are tied into interactions that I have programmed in the Wix Velo javascript language.

I want to be able to run this code when the page loads:

clevertap.event.push(“Page Viewed”, {
“name”: “XYZ”,
“activeCount”: 33,
“Status”: “open”,
});

and I want to run this code when a button is clicked on:

clevertap.event.push(“Button clicked”, {
“name”: “Ab”,
“ping”: “up”,
});

But when I run this, I get clevertap is not defined

I also tried accessing the window object from Velo code, but I discovered that was a no-go. I tried using the wixWindow too, but I wasn’t sure how to get to the (externally loaded) clevertap object.

The solution for implementing JS here is incomplete because it can only load HEAD and BODY javascript and does not seem to be able to be hooked up to tracking events (like clicks on the page). Am I missing something? Is there a better way to do this?

You can’t call this function from the Velo page code and you can’t access the DOM from there.
You can try doing it via a custom element (which can communicate with the page code using setAttribute ).

Also ha a read:

https://support.wix.com/en/article/velo-tutorial-sending-tracking-and-analytics-events

@jonatandor35 Ok so this actually my alternative solution. Just to confirm, 1) use the Wix trackEvent to send the events to GTM, then 2) use GTM to send the events onto the 3rd party tracking platform?

@jason26653 As a matter of fact I’ve never done it on Wix, so I can’t confirm anything before I try it, but I think that if you follow the instructions in the linked page you’ll find the way. If it works for you, it will be nice if you post the step here so other people will be able to implement it.

So annoying that you can’t do this in the way you are describing above, which would make sense.

I have been trying to do it with Segment but to no avail.

Will have to try via a custom element I guess. What a muck around.