Tracking.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. class AC_Tracking extends ActiveCampaign {
  3. public $version;
  4. public $url_base;
  5. public $url;
  6. public $api_key;
  7. function __construct($version, $url_base, $url, $api_key) {
  8. $this->version = $version;
  9. $this->url_base = $url_base;
  10. $this->url = $url;
  11. $this->api_key = $api_key;
  12. }
  13. /*
  14. * Update the status (enabled or disabled) for site tracking.
  15. */
  16. function site_status($params, $post_data) {
  17. // version 2 only.
  18. $request_url = "{$this->url_base}/track/site";
  19. $response = $this->curl($request_url, $post_data, "POST", "tracking_site_status");
  20. return $response;
  21. }
  22. /*
  23. * Update the status (enabled or disabled) for event tracking.
  24. */
  25. function event_status($params, $post_data) {
  26. // version 2 only.
  27. $request_url = "{$this->url_base}/track/event";
  28. $response = $this->curl($request_url, $post_data, "POST", "tracking_event_status");
  29. return $response;
  30. }
  31. /*
  32. * Returns existing whitelisted domains.
  33. */
  34. function site_list($params) {
  35. if ($this->version == 1) {
  36. // not supported currently.
  37. //$request_url = "{$this->url}&api_action=contact_delete_list&api_output={$this->output}&{$params}";
  38. } elseif ($this->version == 2) {
  39. $request_url = "{$this->url_base}/track/site";
  40. }
  41. $response = $this->curl($request_url, array(), "GET", "tracking_site_list");
  42. return $response;
  43. }
  44. /*
  45. * Returns existing tracked events.
  46. */
  47. function event_list($params) {
  48. if ($this->version == 1) {
  49. // not supported currently.
  50. //$request_url = "{$this->url}&api_action=contact_delete_list&api_output={$this->output}&{$params}";
  51. } elseif ($this->version == 2) {
  52. $request_url = "{$this->url_base}/track/event";
  53. }
  54. $response = $this->curl($request_url, array(), "GET", "tracking_event_list");
  55. return $response;
  56. }
  57. /*
  58. * Adds a domain to the site tracking whitelist.
  59. */
  60. function whitelist($params, $post_data) {
  61. // version 2 only.
  62. $request_url = "{$this->url_base}/track/site";
  63. $response = $this->curl($request_url, $post_data, "PUT", "tracking_whitelist");
  64. return $response;
  65. }
  66. /*
  67. * Removes a domain from the site tracking whitelist.
  68. */
  69. function whitelist_remove($params, $post_data) {
  70. // version 2 only.
  71. $request_url = "{$this->url_base}/track/site";
  72. $response = $this->curl($request_url, $post_data, "DELETE", "tracking_whitelist");
  73. return $response;
  74. }
  75. /*
  76. * Removes an event.
  77. */
  78. function event_remove($params, $post_data) {
  79. // version 2 only.
  80. $request_url = "{$this->url_base}/track/event";
  81. $response = $this->curl($request_url, $post_data, "DELETE", "tracking_event_remove");
  82. return $response;
  83. }
  84. /*
  85. * Adds a new event.
  86. */
  87. function log($params, $post_data) {
  88. $request_url = "https://trackcmp.net/event";
  89. $post_data["actid"] = $this->track_actid;
  90. $post_data["key"] = $this->track_key;
  91. $visit_data = array();
  92. if ($this->track_email) {
  93. $visit_data["email"] = $this->track_email;
  94. }
  95. if (isset($post_data["visit"])) {
  96. $visit_data = array_merge($visit_data, $post_data["visit"]);
  97. }
  98. if ($visit_data) {
  99. $post_data["visit"] = json_encode($visit_data);
  100. }
  101. $response = $this->curl($request_url, $post_data, "POST", "tracking_log");
  102. return $response;
  103. }
  104. }
  105. ?>