Sending Events to Google Analytics

I am looking to send commands to the Google Analytics API from the Developers Tool “About Page Code” view.

  1. By default, do we have access to the Google Analytics API or does that need to be switched on? From Yoav’s comments, it seems like we need to ask for access: https://www.wix.com/code/home/forum/questions-answers/wix-apps-other-events-google-analytics-adwods-tracking
  2. Is there an example snippet of code that documents what we need to enter in the “About Page Code” view in order to fire off a ga() event to Google Analytics? I’ve included a sample of the event I wanted to trigger when someone clicks on a button:

$w.onReady(function () {
//TODO: write your page related code here…
});
export function button1_click(event) {
//Add your code for this event here:
ga(‘send’,‘event’, {eventCategory:‘Start Questionnaire’,eventAction:‘From Nav Menu’,eventValue:‘100’,eventLabel:event.target.href,transport:‘beacon’});
}

2 Likes

I just wanted to write to make sure this inquiry didn’t fall through the cracks. Yoav: can you grant me access to the Google Analytics API so that I can send events to GA when somone clicks on a button or views specific buttons on my landing page? As of now the ga() function is not recognized even though analytics.js is loaded on the page from WIX

Hi Ron,
First of all, I’m assuming you’re trying to get analytics on clicks or some other in-page events, right? Because there’s an easier route if all you want to do is follow page views.
There not yet any pre-canned code support for GA, but you can code it yourself. I think what Yoav meant to convey was that this was something we could look into adding in the future.
In the meantime, you could try to roll it yourself with JavaScript as it seems you’re doing. But it seems like you’ve pasted in some code which isn’t really following the WixCode JavaScript conventions. Also, it looks like you’re calling a function called ga() which I don’t see implemented in your code.

Here’s a link to get started coding JS within Wix Code

Thanks for the note Uval. I have a 5-page mobile website with most of the content on the first landing page. I have already setup to track pageviews, however, that falls far short of understanding how users move through a site. It would be much more relevant to track button clicks and when certain items on the landing page come into view. For anyone who is doing paid marketing, this is a must.

Is Google Analytic’s analytics.js embedded on every WIX page? I am looking to embed ga() call functions for OnClick and OnViewportEnter so that I can send events to Google Analytics for processing:

export function button1_click(event) {
ga(‘send’,‘event’, {eventCategory:‘Start Questionnaire’,eventAction:‘From Nav Menu’,eventValue:‘100’,eventLabel:event.target.href,transport:‘beacon’});
}

In HTML, the ga() works fine since at the section of the page, I call analytics.js. Can you please advise what I am to do to fire off a ga() event to analytics.js? Alternately, is it ok if I call analytics.js in the “About Page Code” view? I am just afraid that it is already called in the WIX basecode. The implementation code I normally embed in the is:

$w.onReady(function () {
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,‘script’,‘https://www.google-analytics.com/analytics.js’,'ga’);
});

You can see that the ga() function is declared here in this script. I presume WIX basecode already has this. Do you have any examples of how we can call this Google Analytics analytics.js function? Perhaps you renamed it something else?

Joining Ron, sending ga events is super critical for me as well, is there a solution how to it? thanks!

bump

count me in on this, need it pronto.

Hay all,

Quick update - we are working on exposing the ga APIs to report analytics.
Any other analytics tools you need us to support (keep in mind, we are also working on facebook and tag manager…)

Facebook and Google Analytics are the biggest platforms. DCM is also big but I suspect that most people who are using WIX to host their sites are not paying for DCM. GTM may be a Pandora’s box as it may be a backdoor to put in code that interferes with WIX base code so I suspect this is not something the WIX team would entertain.

Google Analytics is a priority for me as well.
In other occasions I’ve been using MixPanel, also a very popular and powerful analytics tool.
embedding ga() calls within WixCode would be a great feature, so we can trigger it in any logical event.

Adding it from the UI by right clicking links/buttons would be even better for people that are less savvy with code…

Honestly, to add to the bigger picture, we do have other 3rd party needs that are currently not met very well related to events and analytics that mostly arise out of our inability to incorporate their scripts in the section of our site.

In fact, many of the tools I use, for this reason, have remained fully incompatible with Wix over the years.

Another use case we totally have is currently forced through ghetto-rigged mode of doing things with inferior or incomplete results: that use is A/B testing. Virtually all such solutions do require script injection to head section. https://help.optimizely.com/Get_Started/Get_started_on_web_optimization

Perhaps, if there are technical or security concerns, you guys can find ways to natively offer us integrations with such tools through your awesome business development and partnerships arm, or perhaps develop an extra feature that needs to be enabled with some disclosures to the end users who may have no idea what they may be doing. Or perhaps such requests can be handled by support ONLY instead even, and there can be a list of approved scripts to use and what not, maybe even an AI like the URL troubleshooter can have a list of approved scripts and how they look like and there can be process for us to use that tool to add what we need and what is approved to the script without breaking anything. or ever running that risk, with the AI being able to identify anything that is broken or should not go into head section per Wix approvals.

This is the biggest impediment I have on Wix sites when it comes to ROI of our marketing and SEO activities. It makes my life so much easier if I can have these advanced abilities and it will turn my results and reports much more accurate and reliable than they currently are for WIX SITES ONLY. A/B testing and other affairs like it that use similar methods to integrate can also help me improve our SEO and marketing/campaign performance with much more agility and accuracy than my current methodologies.

But Google tag manager and events tracking is a very very good start.

Thanks & please keep up the good work!
Omid

I would love to see Wix support for GA tracking and also A/B testing.

Hi guys,
We’ve released a new Track & Analyze tool. Click here to learn more about it.
For further help contact Wix support team .

Have a great day,
Tal.

This is Great stuff and speed guys. I was also just notified HOTJAR is now compatible with Wix.

Now I do have one question: Exactly how does the “Google Adwords” analytics help me, what does it do now that we could not do before? And where can I exactly see its results? I am just curious as it was announced and made available but I find no documentation on it and on what it is supposed to do precisely?

Adding Custom Code to Your Site | Help Center | Wix.com (it’s just one line and 2 words, Google Adwords, not details on it)

Thanks

Hi Omid,
For questions about it, please contact Wix support team as they know best :slight_smile:

Thanks,
Tal.