public function testGetVisitorId() { $cookies = $_COOKIE; unset($_COOKIE[\JDI\TntAffiliate\TntAffiliate::VISITOR_COOKIE]); $this->assertNull(\JDI\TntAffiliate\TntAffiliate::getVisitorId()); $vid = 'VID:TEST:VISITOR'; $_COOKIE[\JDI\TntAffiliate\TntAffiliate::VISITOR_COOKIE] = $vid; $this->assertEquals($vid, \JDI\TntAffiliate\TntAffiliate::getVisitorId()); $_COOKIE = $cookies; }
/** * Create a new visitor ID * * @param string $productId TNTs Product ID for the visitor * @param string $clientIp IP Address of the client * @param string $type Traffic Type e.g. Direct * @param bool $setCookie Set the Cookie on the clients device * @param string $cookieDomain Domain to set the cookie on, recommended to .yourdomain.tld * * @return string Visitor ID */ public function createVisitorId($productId, $clientIp = null, $type = 'direct', $setCookie = false, $cookieDomain = null) { if ($clientIp === null) { $clientIp = TntAffiliate::getClientIp(); } $visitorId = $this->_clientPost('visitors/create-id', ['type' => $type, 'client_ip' => $clientIp, 'product' => $productId, 'cookie_domain' => $cookieDomain])->getResult(); if ($setCookie) { setcookie('TNT:VID', $visitorId, 2592000, '/', $cookieDomain); } return $visitorId; }