0

I am trying to track event on success of $.ajax function and then redirect the page. Unfrotunatly the tracking wont appear on analytics and I belive this is because my redirect wont let the tracking finish it's job. I heard I can detect when data is passed to google analytics but could not figure it out.

$.ajax({
                type : "POST",
                url : formActionAttr,
                data : datastring,
                success : function() {                                                                                          

                    //analytics tracking                                        
                    _gaq.push(['_trackEvent', 'Category 1', 'Success', formActionAttr]);                                                    

                    window.location.href = pdfurl;                                                                      

                }

                });

appreciate any help!

devjs11
  • 1,898
  • 7
  • 43
  • 73

1 Answers1

3

Use Google Analytic's hitCallback function:

success: function(){
    _gaq.push(['_set','hitCallback',function(){

        window.location.href = pdfurl;

    }]);

    _gaq.push(['_trackEvent','Category 1','Success',formActionAttr]);

}
Community
  • 1
  • 1
Blexy
  • 9,573
  • 6
  • 42
  • 55