1

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);
    }
};
?>`
Ellenfih
  • 11
  • 4
  • ``curl`` is used to handle requests from your domain to another domain in PHP because you can not usually do AJAX calls to a different domain. If you are calculating button clicks in your own website, you do not need to use ``curl`` at all. – Dula Oct 12 '21 at 03:06

1 Answers1

0

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
  });
});
Dula
  • 1,276
  • 5
  • 14
  • 23
  • Hello, thank you for your reply. are you have any example for the "data" section there? – Ellenfih Oct 28 '21 at 06:19
  • ``data :{actid: "Actid", key: "key", event: "event_name", visit: ["v1","v2","v3"]}`` – Dula Oct 28 '21 at 06:30
  • Thank you for your answer again. I think I have one last question here. For the visit part, if I want to set an email variable, can I only set a specific email variable to trigger the event? For example, if I want to know who visits my page and triggers events on my page, how do I know who (email) triggers the event on my page? – Ellenfih Oct 31 '21 at 05:57
  • I think, then you will have to pass the email through and capture it in PHP side or maybe you can set a session variable on user login and access it in your PHP script! – Dula Oct 31 '21 at 21:33
  • Thank you so much for your patience. Actually, I want to capture who visits my page without a user login and also not to capture only the specific email that I identified in my coding. Is it possible to have another way of doing this? – Ellenfih Nov 08 '21 at 14:21
  • Without a login, you can not get data like email from the user unless you provide a form and ask them to fill it out. – Dula Nov 08 '21 at 22:33
  • Thank you once more. In conclusion, I need to use PHP code on the server side and an AJAX call on the client side to execute this PHP code. Then, to see which client is doing the action on my website, must via log in or fill in the form to track them. Is it? – Ellenfih Nov 17 '21 at 05:24