0

I have jQuery that through msg back to the div with particular ID.

here is part of the code:

$(function(){
    $('#contactform').submit(function(){
        $.ajax({
            url:'result.php',
            type : 'POST',
            dataType: 'json',
            data: $(this).serialize(),
            success: function(data){
                if(data.error){
                    $('#error').text(data.reg_error)
                    $('#reg_error').load('msg/return_msg1.php');
                };
...

So what i need is just inform google analytics about this event through smth like:

ga(‘send’, ’event’, ’string1’, ’string2’, ’Failed’);

How can i do that correctly?

Don Korleone
  • 321
  • 2
  • 3
  • 9
  • 1
    A 2-second google search would find you an answer. http://davidwalsh.name/ajax-analytics – Diodeus - James MacFarlane Aug 19 '14 at 21:23
  • I could not find the answer for my question here. The point was i have several else's of that error throwing and want google analytics catch that error. – Don Korleone Aug 19 '14 at 21:32
  • I think you need to re-state your question in that case. – Diodeus - James MacFarlane Aug 19 '14 at 21:33
  • My question is clear "I have working script and need to inform google analytics about what kind of event happened when user performed any kind of act with contact form" – Don Korleone Aug 19 '14 at 21:42
  • Hook into the Global ajax settings to set defaults. see: http://stackoverflow.com/questions/8539897/using-google-analytics-to-track-ajax-requests – BReal14 Aug 19 '14 at 21:45
  • Just a note regarding syntax. In your ga('send'....) call, make sure you use the straight, single quotes. What you pasted above uses the non-standard quotes and might not work for GA. – nyuen Aug 20 '14 at 16:32
  • nyuen thank you for advice. I didn't even pay attention to that. Now my entire jquery works fine. But here is the next question. How i can be sure that google analytics accepts that particular event? – Don Korleone Aug 20 '14 at 18:13

0 Answers0