On previous versions of this module (8.2.x) I could use the "ga" library to send events to analytics like this:

ga('send', 'event', {
            'eventCategory': 'Downloads',
            'eventAction': 'PDF',
            'eventLabel': href
});

Now the "ga" library is not defined.
How can I reuse this code to send events to analytics?

Thanks,
Sergio

Comments

arrubiu created an issue. See original summary.

gaurav.bajpai’s picture

Hi,

I am facing similar issue with current dev version 8.3.x, so is there any plan to use method gtag instead ga?
The custom events are working with method gtag.

andyrigby’s picture

Hi,

In the 3.x version of the module the gtag library is used. You should be able to create events from custom javascript: https://developers.google.com/analytics/devguides/collection/gtagjs/events

If this doesn't answer your question please could you expand a little on the issue you are seeing?

Thanks,
Andy.

japerry’s picture

Status: Active » Fixed

Yup, you can implement your own JS or use the events system in the 4.x version to do it in php code:
See below as an example.
https://git.drupalcode.org/project/google_analytics/-/blob/4.x/src/Event...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.