简体   繁体   中英

All my events sent to Google Analytics are undefined

I'm trying to set up "goals" for Google Analytics on a client wordpress. I'm not a big fan of plugins etc but that's on what I have to work.

So the client wants to analyse his forms (made with Contact Form 7). Contact form 7 allows you to execute a script when the form is send.

Here is the script I use when the form is completed

document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('event', 'mail', {
  'event_category' : 'sent',
  'event_label' : 'test'
});
}, false);

In Google analytics I get the event but all values are "undefined"

Based on the developer guide , the syntax for sending events is the following. There is a send command, and hit type is specified as a second argument, followed by event details.

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

So in your case you should use this code:

document.addEventListener( 'wpcf7mailsent', function( event ) {
  ga('send', 'event', 'sent', 'mail', 'test');
}, false);

Your current syntax is more similar to that of GTAG version of tracking, which is based on the gtag() object:

gtag('event', <action>, {
  'event_category': <category>,
  'event_label': <label>,
  'value': <value>
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM