How to track event for Event Tracking Activecampaign

371 Views Asked by At

may I ask how to track the specific event with the event tracking ActiveCampaign code?` For example, if I want to track button clicks on my own website, how do I add on in this php sample code here.

Thank you.

<?php


// initializes a cURL session
    $curl = curl_init();

    // changes the cURL session behavior with options
    curl_setopt($curl, CURLOPT_URL, "https://trackcmp.net/event");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, array(
    "actid" => "Actid",
    "key" => "Key",
    "event" => "EVENT NAME",
     "eventdata" => "Button click login",
    "visit" => json_encode(array(
            // If you have an email address, assign it here.
            "email" => "",
)),
        ));

    //execute
    $result = curl_exec($curl);
    if ($result !== false) {
        $result = json_decode($result);
        if ($result->success) {
            echo 'Success! ';
        } else {
            echo 'Error! ';
        }

        echo $result->message;
    } else {
        echo 'cURL failed to run: ', curl_error($curl);
    }
};
?>`

1

There are 1 best solutions below

7
On

You will have to use AJAX and send a request to execute this segment of code on all the buttons you want to track the click event.

$(".tracked-button").on('click', function () {
  // fire the AJAX request on button click
  $.ajax({
     type: "POST",
     url: 'YOUR URL',
     dataType: 'json',
     headers: {},
     data: {}
  })
  .done(function (response) {
     // if you want to do something on success
  })
  .fail(function (xhr, status, error) {
     // if you want to do something on error
  });
});