Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавлен метод загрузки визитов веб-аналитики #184

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/Model/Entity/WebAnalytics/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @category Page
* @package RetailCrm\Api\Model\Entity\WebAnalytics
*/

namespace RetailCrm\Api\Model\Entity\WebAnalytics;

use RetailCrm\Api\Component\Serializer\Annotation as JMS;

/**
* Class Page
*
* @category Page
* @package RetailCrm\Api\Model\Entity\WebAnalytics
*/
class Page
{
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("url")
*/
public $url;

/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("title")
*/
public $title;

/**
* @var int
*
* @JMS\Type("integer")
* @JMS\SerializedName("countViews")
*/
public $countViews;

/**
* @var int
*
* @JMS\Type("integer")
* @JMS\SerializedName("timeOnPage")
*/
public $timeOnPage;
}
107 changes: 107 additions & 0 deletions src/Model/Entity/WebAnalytics/Visit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* @category Visit
* @package RetailCrm\Api\Model\Entity\WebAnalytics
*/

namespace RetailCrm\Api\Model\Entity\WebAnalytics;

use RetailCrm\Api\Component\Serializer\Annotation as JMS;

/**
* Class Visit
*
* @category Visit
* @package RetailCrm\Api\Model\Entity\WebAnalytics
*/
class Visit
{
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("createdAt")
*/
public $createdAt;

/**
* @var int
*
* @JMS\Type("integer")
* @JMS\SerializedName("visitLength")
*/
public $visitLength;

/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("exitPage")
*/
public $exitPage;

/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("landingPage")
*/
public $landingPage;

/**
* @var int
*
* @JMS\Type("integer")
* @JMS\SerializedName("pageViews")
*/
public $pageViews;

/**
* @var int
*
* @JMS\Type("integer")
* @JMS\SerializedName("pageDepth")
*/
public $pageDepth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У текущей и у $pageViews и $visitLength должны быть числовые типы.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У $pageDepth не исправлено.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поправил


/**
* @var Customer
*
* @JMS\Type("RetailCrm\Api\Model\Entity\WebAnalytics\Customer")
* @JMS\SerializedName("customer")
*/
public $customer;

/**
* @var Source
*
* @JMS\Type("string")
* @JMS\SerializedName("source")
*/
public $source;

/**
* @var Page[]
*
* @JMS\Type("array<RetailCrm\Api\Model\Entity\WebAnalytics\Page>")
* @JMS\SerializedName("pages")
*/
public $pages;

/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("clientId")
*/
public $clientId;

/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("site")
*/
public $site;
}
41 changes: 41 additions & 0 deletions src/Model/Request/WebAnalytics/VisitsUploadRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @category VisitsUploadRequest
* @package RetailCrm\Api\Model\Request\WebAnalytics
*/

namespace RetailCrm\Api\Model\Request\WebAnalytics;

use RetailCrm\Api\Component\FormData\Mapping as Form;
use RetailCrm\Api\Interfaces\RequestInterface;

/**
* Class VisitsUploadRequest
*
* @category VisitsUploadRequest
* @package RetailCrm\Api\Model\Request\WebAnalytics
*/
class VisitsUploadRequest implements RequestInterface
{
/**
* @var \RetailCrm\Api\Model\Entity\WebAnalytics\Visit[]
*
* @Form\Type("array<RetailCrm\Api\Model\Entity\WebAnalytics\Visit>")
* @Form\SerializedName("visits")
* @Form\JsonField()
*/
public $visits;

/**
* VisitsUploadRequest constructor.
*
* @param \RetailCrm\Api\Model\Entity\WebAnalytics\Visit[]|null $visits
*/
public function __construct(?array $visits = null)
{
if (null !== $visits) {
$this->visits = $visits;
}
}
}
30 changes: 30 additions & 0 deletions src/Model/Response/WebAnalytics/VisitsUploadResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* PHP version 7.3
*
* @category SourcesUploadResponse
* @package RetailCrm\Api\Model\Response\WebAnalytics
*/

namespace RetailCrm\Api\Model\Response\WebAnalytics;

use RetailCrm\Api\Component\Serializer\Annotation as JMS;
use RetailCrm\Api\Model\Response\SuccessResponse;

/**
* Class VisitsUploadResponse
*
* @category VisitsUploadResponse
* @package RetailCrm\Api\Model\Response\WebAnalytics
*/
class VisitsUploadResponse extends SuccessResponse
{
/**
* @var \RetailCrm\Api\Model\Entity\WebAnalytics\Visit[]
*
* @JMS\Type("array<RetailCrm\Api\Model\Entity\WebAnalytics\Visit>")
* @JMS\SerializedName("failedVisits")
*/
public $failedVisits;
}
95 changes: 95 additions & 0 deletions src/ResourceGroup/WebAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Model\Request\WebAnalytics\ClientIdUploadRequest;
use RetailCrm\Api\Model\Request\WebAnalytics\SourcesUploadRequest;
use RetailCrm\Api\Model\Request\WebAnalytics\VisitsUploadRequest;
use RetailCrm\Api\Model\Response\WebAnalytics\ClientIdUploadResponse;
use RetailCrm\Api\Model\Response\WebAnalytics\SourcesUploadResponse;
use RetailCrm\Api\Model\Response\WebAnalytics\VisitsUploadResponse;

/**
* Class WebAnalytics
Expand Down Expand Up @@ -173,4 +175,97 @@ public function clientIdsUpload(ClientIdUploadRequest $request): ClientIdUploadR

return $response;
}

/**
*
* Makes POST "/api/v5/web-analytics/client-ids/upload" request.
*
* Example:
* ```php
* use RetailCrm\Api\Factory\SimpleClientFactory;
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
* use RetailCrm\Api\Model\Entity\WebAnalytics\Visit;
* use RetailCrm\Api\Model\Entity\WebAnalytics\Customer;
* use RetailCrm\Api\Model\Request\WebAnalytics\VisitsUploadRequest;
*
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
*
* $entity = new Visit();
* $dateTime = new \DateTime('2023-12-06T12:00:00');
* $entity->createdAt = $dateTime->format('Y-m-d H:i:s');
* $entity->visitLength = 10;
* $entity->exitPage = '/exit-page';
* $entity->landingPage = '/landing-page';
* $entity->pageViews = 5;
* $entity->pageDepth = 3;
* $entity->customer = new Customer();
* $entity->customer->id = 10;
* $entity->customer->externalId = 'externalId';
* $entity->source = new Source();
* $entity->source = "sourse";
* $entity->medium = "medium";
* $entity->campaign = "campaign";
* $entity->keyword = "keyword";
* $entity->content = "content";
* $page1 = new Page();
* $page1->url = ('/page1');
* $page1->title = ('Page 1');
* $page1->countViews = 2;
* $page1->timeOnPage = 60;
* $page2 = new Page();
* $page2->url = ('/page2');
* $page2->title = ('Page 2');
* $page2->countViews = 3;
* $page2->timeOnPage = 45;
* $pages = [$page1, $page2];
* $entity->pages = $pages;
* $entity->clientId = '123456';
* $entity->site = 'example.com';
*
* $request = new VisitsUploadRequest([$entity]);
*
* try {
* $response = $client->webAnalytics->visitsUpload($request);
* } catch (ApiExceptionInterface $exception) {
* echo sprintf(
* 'Error from RetailCRM API (status code: %d): %s',
* $exception->getStatusCode(),
* $exception->getMessage()
* );
*
* if (count($exception->getErrorResponse()->errors) > 0) {
* echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
* }
*
* return;
* }
*
* echo 'Upload is successful';
* ```
*
* @param \RetailCrm\Api\Model\Request\WebAnalytics\VisitsUploadRequest $request
*
* @return \RetailCrm\Api\Model\Response\WebAnalytics\VisitsUploadResponse
* @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface
* @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface
* @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException
* @throws \RetailCrm\Api\Exception\Api\ApiErrorException
* @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException
* @throws \RetailCrm\Api\Exception\Api\MissingParameterException
* @throws \RetailCrm\Api\Exception\Api\ValidationException
* @throws \RetailCrm\Api\Exception\Client\HandlerException
* @throws \RetailCrm\Api\Exception\Client\HttpClientException
*/
public function visitsUpload(VisitsUploadRequest $request): VisitsUploadResponse
{
/** @var VisitsUploadResponse $response */
$response = $this->sendRequest(
RequestMethod::POST,
'web-analytics/visits/upload',
$request,
VisitsUploadResponse::class
);

return $response;
}
}
Loading
Loading