D
D
Darklt2019-05-23 18:00:30
Google Analytics
Darklt, 2019-05-23 18:00:30

Why doesn't ga work in ajax?

I created a goal in GA

I write in ajax form submission:

$.ajax({
                url: "/frmVopros.php",
                data: {
                    name: $(".f").val(),
                    phone: $(".fп2").val(),
                    vopros: $(".fo3").val(),
                    cururl: document.location.href,
                    title: document.title
                },
                type: "GET",
                success: function(t) {
            console.log( "Request Succied" );
            ga('send', 'event', 'submit', 'btn');


and does not work, if you do this: for example
window.location.href = "?ok";, and instead of an event put a transition to the address, then it works .... maybe the Guru will tell you what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-05-23
@OlegFrontend

To begin with, the code must be brought to the proper form. even if he falls.

$.ajax({
  url: "/frmVopros.php",
  data: {
    name: $(".f").val(),
    phone: $(".fп2").val(),
    vopros: $(".fo3").val(),
    cururl: document.location.href,
    title: document.title
  },
  type: "GET",
  success: function (t) {
    console.log("Request Succied");
    ga('send', 'event', 'submit', 'btn');
  }
});

Next, is ga a global function?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question