src/Manager/Webfactory/StatistiquesManager.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Manager\Webfactory;
  3. use Container20kufZJ\getDoctrine_DatabaseDropCommandService;
  4. use DateTime;
  5. use JetBrains\PhpStorm\NoReturn;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  10. use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
  11. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  12. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  13. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  14. use Symfony\Contracts\HttpClient\HttpClientInterface;
  15. use Symfony\Contracts\HttpClient\ResponseInterface;
  16. class StatistiquesManager
  17. {
  18.     private string $urlAt;
  19.     private string $apiKey;
  20.     private string $beginDate;
  21.     private string $endDate;
  22.      public function __construct(private readonly SessionInterface $session, private readonly HttpClientInterface $httpClient, private readonly ParameterBagInterface $parameters, private readonly Security $security)
  23.     {
  24.         $this->urlAt 'https://api.atinternet.io/v3/data/getData';
  25.         $this->beginDate = (new DateTime('first day of last month'))->format('Y-m-d'); // 1er jour du mois dernier
  26.         $this->endDate = (new DateTime('last day of last month'))->format('Y-m-d');// dernier jour du mois dernier
  27.         $this->apiKey $this->parameters->get('api_atinternet_key');
  28.     }
  29.     /**
  30.      * @throws TransportExceptionInterface
  31.      * @throws ServerExceptionInterface
  32.      * @throws RedirectionExceptionInterface
  33.      * @throws DecodingExceptionInterface
  34.      * @throws ClientExceptionInterface
  35.      */
  36.     public function getAllStatistiques($pianoId$advancedSats$lang 'FR'$magasin$beginDate null$endDate null): array
  37.     {
  38.         $dates = [
  39.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  40.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  41.         ];
  42.         $statsNbPagesVues $this->getNbPagesVues($pianoId$lang$magasin$dates['start'], $dates['end']);
  43.         $statsNbVisiteurs $this->getNbVisiteurs($pianoId$lang$magasin$dates['start'], $dates['end']);
  44.         $statsNbpagesVuesParVisites $this->getNbPagesVuesParVisite($pianoId$lang$magasin$dates['start'], $dates['end']);
  45.         $typeAppareils $this->getTypesAppareils($pianoId$lang$magasin$dates['start'], $dates['end']);
  46.         $typesSources $this->getTraficSources($pianoId$lang$magasin$dates['start'], $dates['end']);
  47.         $topPagesLastMonth $this->getTopPagesVues($pianoId$advancedSats$lang$magasin$dates['start'], $dates['end']);
  48.         if ($advancedSats) {
  49. //            $topSecteurs = $this->getTraficCities($pianoId, $lang, $magasin, $dates['start'], $dates['end']);
  50.             $tempsMoyenSession $this->getAverageLengthBySession($pianoId$lang$magasin$dates['start'], $dates['end']);
  51.             $clicksCtas $this->getAllCta($pianoId$lang$magasin$dates['start'], $dates['end']);
  52.             $clicksSocialMedia $this->getAllClicksSocialMedia($pianoId$lang$magasin$dates['start'], $dates['end']);
  53.             return [
  54.                 'pages_vues' => $statsNbPagesVues,
  55.                 'visiteurs' => $statsNbVisiteurs,
  56.                 'pages_vues_par_visites' => $statsNbpagesVuesParVisites,
  57.                 'dureeSession' => $tempsMoyenSession,
  58. //                'topSecteurs' => json_encode($topSecteurs),
  59.                 'typesAppareils' => json_encode($typeAppareils),
  60.                 'typesSources' => json_encode($typesSources),
  61.                 'topPages' => $topPagesLastMonth,
  62.                 'clicks_ctas' => $clicksCtas,
  63.                 'clicks_socials' => $clicksSocialMedia
  64.             ];
  65.         }
  66.         return [
  67.             'pages_vues' => $statsNbPagesVues,
  68.             'visiteurs' => $statsNbVisiteurs,
  69.             'pages_vues_par_visites' => $statsNbpagesVuesParVisites,
  70.             'typesAppareils' => json_encode($typeAppareils),
  71.             'typesSources' => json_encode($typesSources),
  72.             'topPages' => $topPagesLastMonth
  73.         ];
  74.     }
  75.     /**
  76.      * Récupére le nombre de pages vues
  77.      * @throws TransportExceptionInterface
  78.      * @throws ServerExceptionInterface
  79.      * @throws RedirectionExceptionInterface
  80.      * @throws DecodingExceptionInterface
  81.      * @throws ClientExceptionInterface
  82.      */
  83.     public function getNbPagesVues($pianoId$lang$magasin$beginDate null$endDate null)
  84.     {
  85.         $nbPagesVues 0;
  86.         $dates = [
  87.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  88.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  89.         ];
  90.         $postDatas = [
  91.             'columns' => ['event_name''proprietary''lang_version''m_page_loads'],
  92.             'sort' => ['-m_page_loads'],
  93.             'filter' => [
  94.                 'property' => [
  95.                     '$AND' => [
  96.                         [
  97.                             'event_name' => [
  98.                                 '$eq' => 'page.display'
  99.                             ]
  100.                         ],
  101.                         [
  102.                             'proprietary' => [
  103.                                 '$eq' => $magasin
  104.                             ]
  105.                         ],
  106.                         [
  107.                             'lang_version' => [
  108.                                 '$eq' => $lang
  109.                             ]
  110.                         ]
  111.                     ]
  112.                 ]
  113.             ],
  114.             'space' => ['s' => [intval($pianoId)]],
  115.             'period' => [
  116.                 'p1' => [
  117.                     [
  118.                         'type' => 'D',
  119.                         'start' => $dates['start'],
  120.                         'end' => $dates['end']
  121.                     ]
  122.                 ]
  123.             ],
  124.             'max-results' => 50,
  125.             'page-num' => 1,
  126.             'options' => ['ignore_null_properties' => true'eco_mode' => true]
  127.         ];
  128.         $response $this->getResponse($postDatas);
  129.         if ($response->getStatusCode() === 200) {
  130.             $datas $response->toArray();
  131.             foreach ($datas['DataFeed']['Rows'] as $row) {
  132.                 if ($row['event_name'] == 'page.display') {
  133.                     $nbPagesVues $row['m_page_loads'];
  134.                     break;
  135.                 }
  136.             }
  137.         }
  138.         return $nbPagesVues;
  139.     }
  140.     /**
  141.      * Récupére la durée moyenne d'une session
  142.      * @throws TransportExceptionInterface
  143.      * @throws ServerExceptionInterface
  144.      * @throws RedirectionExceptionInterface
  145.      * @throws DecodingExceptionInterface
  146.      * @throws ClientExceptionInterface
  147.      */
  148.     public function getAverageLengthBySession($pianoId$lang$magasin$beginDate null$endDate null)
  149.     {
  150.         $dureeMoyenne '0';
  151.         $dates = [
  152.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  153.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  154.         ];
  155.         $postDatas = [
  156.             'columns' => [
  157.                 'event_name',
  158.                 'proprietary',
  159.                 'lang_version',
  160.                 'm_time_spent_per_visits'
  161.             ],
  162.             'sort' => [
  163.                 '-m_time_spent_per_visits'
  164.             ],
  165.             'filter' => [
  166.                 'property' => [
  167.                     '$AND' => [
  168.                         [
  169.                             'proprietary' => [
  170.                                 '$eq' => $magasin
  171.                             ]
  172.                         ],
  173.                         [
  174.                             'lang_version' => [
  175.                                 '$eq' => $lang
  176.                             ]
  177.                         ]
  178.                     ]
  179.                 ]
  180.             ],
  181.             'space' => [
  182.                 's' => [
  183.                     intval($pianoId)
  184.                 ]
  185.             ],
  186.             'period' => [
  187.                 'p1' => [
  188.                     [
  189.                         'type' => 'D',
  190.                         'start' => $dates['start'],
  191.                         'end' => $dates['end']
  192.                     ]
  193.                 ]
  194.             ],
  195.             'max-results' => 50,
  196.             'page-num' => 1,
  197.             'options' => [
  198.                 'ignore_null_properties' => true,
  199.                 'eco_mode' => true
  200.             ]
  201.         ];
  202.         $response $this->getResponse($postDatas);
  203.         if ($response->getStatusCode() === 200) {
  204.             $datas $response->toArray();
  205.             foreach ($datas['DataFeed']['Rows'] as $row) {
  206.                 $dureeMoyenne += $row['m_time_spent_per_visits'];
  207.             }
  208.         }
  209.         if ($dureeMoyenne 0) {
  210.             $datas = ['hours' => intval(gmdate('H', ($dureeMoyenne 1000))), 'minutes' => intval(gmdate('i', ($dureeMoyenne 1000))), 'secondes' => intval(gmdate('s', ($dureeMoyenne 1000)))];
  211.             $dureeMoyenne = ($datas['hours'] > 0) ? $datas['hours'] . ' h ' '';
  212.             $dureeMoyenne .= ($datas['minutes'] > 0) ? $datas['minutes'] . ' min ' '';
  213.             $dureeMoyenne .= ($datas['secondes'] > 0) ? $datas['secondes'] . ' s' '';
  214.         }
  215.         return $dureeMoyenne;
  216.     }
  217.     /**
  218.      * Récupére les différentes villes d'ou viennent le trafic
  219.      * @throws TransportExceptionInterface
  220.      * @throws ServerExceptionInterface
  221.      * @throws RedirectionExceptionInterface
  222.      * @throws DecodingExceptionInterface
  223.      * @throws ClientExceptionInterface
  224.      */
  225.     public function getTraficCities($pianoId$lang$magasin$beginDate null$endDate null): array
  226.     {
  227.         $finalDatas = [];
  228.         $dates = [
  229.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  230.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  231.         ];
  232.         $postDatas = [
  233.             'columns' => [
  234.                 'page',
  235.                 'proprietary',
  236.                 'lang_version',
  237.                 'm_page_loads',
  238.                 'geo_city',
  239.                 'm_visits'
  240.             ],
  241.             'sort' => [
  242.                 '-m_page_loads'
  243.             ],
  244.             'filter' => [
  245.                 'property' => [
  246.                     '$AND' => [
  247.                         [
  248.                             'proprietary' => [
  249.                                 '$eq' => $magasin
  250.                             ]
  251.                         ],
  252.                         [
  253.                             'lang_version' => [
  254.                                 '$eq' => $lang
  255.                             ]
  256.                         ]
  257.                     ]
  258.                 ]
  259.             ],
  260.             'space' => [
  261.                 's' => [
  262.                     intval($pianoId)
  263.                 ]
  264.             ],
  265.             'period' => [
  266.                 'p1' => [
  267.                     [
  268.                         'type' => 'D',
  269.                         'start' => $dates['start'],
  270.                         'end' => $dates['end']
  271.                     ]
  272.                 ]
  273.             ],
  274.             'max-results' => 4,
  275.             'page-num' => 1,
  276.             'options' => [
  277.                 'ignore_null_properties' => true,
  278.                 'eco_mode' => true
  279.             ]
  280.         ];
  281.         $response $this->getResponse($postDatas);
  282.         if ($response->getStatusCode() === 200) {
  283.             $datas $response->toArray();
  284.             foreach ($datas['DataFeed']['Rows'] as $row) {
  285.                 $finalDatas[] = ['ville' => $row['geo_city'], 'visites' => $row['m_visits']];
  286.             }
  287.         }
  288.         return $finalDatas;
  289.     }
  290.     /**
  291.      * Récupére les types d'appareils utilisés (mobile, tablette, ..)
  292.      * @throws TransportExceptionInterface
  293.      * @throws ServerExceptionInterface
  294.      * @throws RedirectionExceptionInterface
  295.      * @throws DecodingExceptionInterface
  296.      * @throws ClientExceptionInterface
  297.      */
  298.     public function getTypesAppareils($pianoId$lang$magasin$beginDate null$endDate null): array
  299.     {
  300.         $finalDatas = [];
  301.         $dates = [
  302.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  303.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  304.         ];
  305.         $postDatas = [
  306.             'columns' => [
  307.                 'device_type',
  308.                 'proprietary',
  309.                 'lang_version',
  310.                 'm_visits'
  311.             ],
  312.             'sort' => [
  313.                 '-m_visits'
  314.             ],
  315.             'filter' => [
  316.                 'property' => [
  317.                     '$AND' => [
  318.                         [
  319.                             'proprietary' => [
  320.                                 '$eq' => $magasin
  321.                             ]
  322.                         ],
  323.                         [
  324.                             'lang_version' => [
  325.                                 '$eq' => $lang
  326.                             ]
  327.                         ]
  328.                     ]
  329.                 ]
  330.             ],
  331.             'space' => [
  332.                 's' => [
  333.                     intval($pianoId)
  334.                 ]
  335.             ],
  336.             'period' => [
  337.                 'p1' => [
  338.                     [
  339.                         'type' => 'D',
  340.                         'start' => $dates['start'],
  341.                         'end' => $dates['end']
  342.                     ]
  343.                 ]
  344.             ],
  345.             'max-results' => 50,
  346.             'page-num' => 1,
  347.             'options' => [
  348.                 'ignore_null_properties' => true,
  349.                 'eco_mode' => true
  350.             ]
  351.         ];
  352.         $response $this->getResponse($postDatas);
  353.         if ($response->getStatusCode() === 200) {
  354.             $datas $response->toArray();
  355.             foreach ($datas['DataFeed']['Rows'] as $row) {
  356.                 $finalDatas[] = ['type' => $row['device_type'], 'visites' => $row['m_visits']];
  357.             }
  358.         }
  359.         return $finalDatas;
  360.     }
  361.     /**
  362.      * Récupére les sources de trafic ( réseaux sociaux, .. )
  363.      * @throws TransportExceptionInterface
  364.      * @throws ServerExceptionInterface
  365.      * @throws RedirectionExceptionInterface
  366.      * @throws DecodingExceptionInterface
  367.      * @throws ClientExceptionInterface
  368.      */
  369.     public function getTraficSources($pianoId$lang$magasin$beginDate null$endDate null): array
  370.     {
  371.         $finalDatas = [];
  372.         $dates = [
  373.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  374.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  375.         ];
  376.         $postDatas = [
  377.             'columns' => [
  378.                 'src',
  379.                 'proprietary',
  380.                 'lang_version',
  381.                 'm_visits'
  382.             ],
  383.             'sort' => [
  384.                 '-m_visits'
  385.             ],
  386.             'filter' => [
  387.                 'property' => [
  388.                     '$AND' => [
  389.                         [
  390.                             'proprietary' => [
  391.                                 '$eq' => $magasin
  392.                             ]
  393.                         ],
  394.                         [
  395.                             'lang_version' => [
  396.                                 '$eq' => $lang
  397.                             ]
  398.                         ]
  399.                     ]
  400.                 ]
  401.             ],
  402.             'space' => [
  403.                 's' => [
  404.                     intval($pianoId)
  405.                 ]
  406.             ],
  407.             'period' => [
  408.                 'p1' => [
  409.                     [
  410.                         'type' => 'D',
  411.                         'start' => $dates['start'],
  412.                         'end' => $dates['end']
  413.                     ]
  414.                 ]
  415.             ],
  416.             'max-results' => 50,
  417.             'page-num' => 1,
  418.             'options' => [
  419.                 'ignore_null_properties' => true,
  420.                 'eco_mode' => true
  421.             ]
  422.         ];
  423.         $response $this->getResponse($postDatas);
  424.         $total 0;
  425.         if ($response->getStatusCode() === 200) {
  426.             $datas $response->toArray();
  427.             foreach ($datas['DataFeed']['Rows'] as $row) {
  428.                 $finalDatas[] = ['type' => $row['src'], 'visites' => $row['m_visits']];
  429.                 $total += $row['m_visits'];
  430.             }
  431.         }
  432.         foreach ($finalDatas as $key => $data) {
  433.             $finalDatas[$key]['pourcent'] = round((($data['visites'] / $total) * 100), 2);
  434.         }
  435.         return $finalDatas;
  436.     }
  437.     /**
  438.      * Récupére les pages les plus vues
  439.      * @throws TransportExceptionInterface
  440.      * @throws ServerExceptionInterface
  441.      * @throws RedirectionExceptionInterface
  442.      * @throws DecodingExceptionInterface
  443.      * @throws ClientExceptionInterface
  444.      */
  445.     public function getTopPagesVues($pianoId$advancedSats$lang$magasin$beginDate null$endDate null): array
  446.     {
  447.         $finalDatas = [];
  448.         $dates = [
  449.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  450.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  451.         ];
  452.         $postDatas = [
  453.             'columns' => [
  454.                 'page',
  455.                 'proprietary',
  456.                 'lang_version',
  457.                 'm_page_loads'
  458.             ],
  459.             'sort' => [
  460.                 '-m_page_loads'
  461.             ],
  462.             'filter' => [
  463.                 'property' => [
  464.                     '$AND' => [
  465.                         [
  466.                             'page' => [
  467.                                 '$empty' => false
  468.                             ]
  469.                         ],
  470.                         [
  471.                             'proprietary' => [
  472.                                 '$eq' => $magasin
  473.                             ]
  474.                         ],
  475.                         [
  476.                             'lang_version' => [
  477.                                 '$eq' => $lang
  478.                             ]
  479.                         ]
  480.                     ]
  481.                 ]
  482.             ],
  483.             'space' => [
  484.                 's' => [
  485.                     intval($pianoId)
  486.                 ]
  487.             ],
  488.             'period' => [
  489.                 'p1' => [
  490.                     [
  491.                         'type' => 'D',
  492.                         'start' => $dates['start'],
  493.                         'end' => $dates['end']
  494.                     ]
  495.                 ]
  496.             ],
  497.             'max-results' => (($advancedSats) ? 10 3),
  498.             'page-num' => 1,
  499.             'options' => [
  500.                 'ignore_null_properties' => true,
  501.                 'eco_mode' => true
  502.             ]
  503.         ];
  504.         $response $this->getResponse($postDatas);
  505.         if ($response->getStatusCode() === 200) {
  506.             $datas $response->toArray();
  507.             foreach ($datas['DataFeed']['Rows'] as $row) {
  508.                 $finalDatas[] = ['url' => $row['page'], 'visites' => $row['m_page_loads']];
  509.             }
  510.         }
  511.         return $finalDatas;
  512.     }
  513.     /**
  514.      * Récupére le nombre de visites
  515.      * @throws TransportExceptionInterface
  516.      * @throws ServerExceptionInterface
  517.      * @throws RedirectionExceptionInterface
  518.      * @throws DecodingExceptionInterface
  519.      * @throws ClientExceptionInterface
  520.      */
  521.     public function getNbVisiteurs($pianoId$lang$magasin$beginDate null$endDate null)
  522.     {
  523.         $nbPagesVues 0;
  524.         $dates = [
  525.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  526.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  527.         ];
  528.         $postDatas = [
  529.             'columns' => [
  530.                 'event_name',
  531.                 'lang_version',
  532.                 'proprietary',
  533.                 'm_unique_visitors'
  534.             ],
  535.             'sort' => [
  536.                 '-m_unique_visitors'
  537.             ],
  538.             'filter' => [
  539.                 'property' => [
  540.                     '$AND' => [
  541.                         [
  542.                             'event_name' => [
  543.                                 '$eq' => 'page.display'
  544.                             ]
  545.                         ],
  546.                         [
  547.                             'lang_version' => [
  548.                                 '$eq' => $lang
  549.                             ]
  550.                         ],
  551.                         [
  552.                             'proprietary' => [
  553.                                 '$eq' => $magasin
  554.                             ]
  555.                         ]
  556.                     ]
  557.                 ]
  558.             ],
  559.             'space' => [
  560.                 's' => [
  561.                     intval($pianoId)
  562.                 ]
  563.             ],
  564.             'period' => [
  565.                 'p1' => [
  566.                     [
  567.                         'type' => 'D',
  568.                         'start' => $dates['start'],
  569.                         'end' => $dates['end']
  570.                     ]
  571.                 ]
  572.             ],
  573.             'max-results' => 50,
  574.             'page-num' => 1,
  575.             'options' => [
  576.                 'ignore_null_properties' => true,
  577.                 'eco_mode' => true
  578.             ]
  579.         ];
  580.         $response $this->getResponse($postDatas);
  581.         if ($response->getStatusCode() === 200) {
  582.             $datas $response->toArray();
  583.             foreach ($datas['DataFeed']['Rows'] as $row) {
  584.                 if ($row['event_name'] == 'page.display') {
  585.                     $nbPagesVues $row['m_unique_visitors'];
  586.                     break;
  587.                 }
  588.             }
  589.         }
  590.         return $nbPagesVues;
  591.     }
  592.     /**
  593.      * Récupére la moyenne des pages vues par visite
  594.      * @throws TransportExceptionInterface
  595.      * @throws ServerExceptionInterface
  596.      * @throws RedirectionExceptionInterface
  597.      * @throws DecodingExceptionInterface
  598.      * @throws ClientExceptionInterface
  599.      */
  600.     public function getNbPagesVuesParVisite($pianoId$lang$magasin$beginDate null$endDate null): float|int
  601.     {
  602.         $nbPagesVues 0;
  603.         $dates = [
  604.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  605.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  606.         ];
  607.         $postDatas = [
  608.             'columns' => [
  609.                 'event_name',
  610.                 'proprietary',
  611.                 'lang_version',
  612.                 'm_page_loads_per_visit'
  613.             ],
  614.             'sort' => [
  615.                 '-m_page_loads_per_visit'
  616.             ],
  617.             'filter' => [
  618.                 'property' => [
  619.                     '$AND' => [
  620.                         [
  621.                             'proprietary' => [
  622.                                 '$eq' => $magasin
  623.                             ]
  624.                         ],
  625.                         [
  626.                             'lang_version' => [
  627.                                 '$eq' => $lang
  628.                             ]
  629.                         ]
  630.                     ]
  631.                 ]
  632.             ],
  633.             'space' => [
  634.                 's' => [
  635.                     intval($pianoId)
  636.                 ]
  637.             ],
  638.             'period' => [
  639.                 'p1' => [
  640.                     [
  641.                         'type' => 'D',
  642.                         'start' => $dates['start'],
  643.                         'end' => $dates['end']
  644.                     ]
  645.                 ]
  646.             ],
  647.             'max-results' => 50,
  648.             'page-num' => 1,
  649.             'options' => [
  650.                 'ignore_null_properties' => true,
  651.                 'eco_mode' => true
  652.             ]
  653.         ];
  654.         $response $this->getResponse($postDatas);
  655.         if ($response->getStatusCode() === 200) {
  656.             $datas $response->toArray();
  657.             foreach ($datas['DataFeed']['Rows'] as $row) {
  658.                 if ($row['event_name'] == 'page.display') {
  659.                     $nbPagesVues round($row['m_page_loads_per_visit']);
  660.                     break;
  661.                 }
  662.             }
  663.         }
  664.         return $nbPagesVues;
  665.     }
  666.     /**
  667.      * Récupére le nombre de clic sur les CTA Y aller, appeler, mail, prise de rdv
  668.      * @throws TransportExceptionInterface
  669.      * @throws ServerExceptionInterface
  670.      * @throws RedirectionExceptionInterface
  671.      * @throws DecodingExceptionInterface
  672.      * @throws ClientExceptionInterface
  673.      */
  674.     public function getAllCta($pianoId$lang$magasin$beginDate null$endDate null): array
  675.     {
  676.         $finalDatas = [
  677.             'clicks_cta_phone' => 0,
  678.             'clicks_cta_mail' => 0,
  679.             'clicks_cta_rdv' => 0,
  680.             'clicks_cta_location' => 0,
  681.         ];
  682.         $dates = [
  683.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  684.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  685.         ];
  686.         $postDatas = [
  687.             'columns' => [
  688.                 'event_name',
  689.                 'click',
  690.                 'proprietary',
  691.                 'lang_version',
  692.                 'm_events'
  693.             ],
  694.             'sort' => [
  695.                 '-m_events'
  696.             ],
  697.             'filter' => [
  698.                 'property' => [
  699.                     '$AND' => [
  700.                         [
  701.                             'event_name' => [
  702.                                 '$eq' => 'click.cta'
  703.                             ]
  704.                         ],
  705.                         [
  706.                             'proprietary' => [
  707.                                 '$eq' => $magasin
  708.                             ]
  709.                         ],
  710.                         [
  711.                             'lang_version' => [
  712.                                 '$eq' => $lang
  713.                             ]
  714.                         ]
  715.                     ]
  716.                 ]
  717.             ],
  718.             'space' => [
  719.                 's' => [
  720.                     intval($pianoId)
  721.                 ]
  722.             ],
  723.             'period' => [
  724.                 'p1' => [
  725.                     [
  726.                         'type' => 'D',
  727.                         'start' => $dates['start'],
  728.                         'end' => $dates['end']
  729.                     ]
  730.                 ]
  731.             ],
  732.             'max-results' => 50,
  733.             'page-num' => 1,
  734.             'options' => [
  735.                 'ignore_null_properties' => true
  736.             ]
  737.         ];
  738.         $response $this->getResponse($postDatas);
  739.         if ($response->getStatusCode() === 200) {
  740.             $datas $response->toArray();
  741.             foreach ($datas['DataFeed']['Rows'] as $row) {
  742.                 if ($row['event_name'] == 'click.cta') {
  743.                     switch ($row['click']) {
  744.                         case 'phone':
  745.                             $finalDatas['clicks_cta_phone'] = $row['m_events'];
  746.                             break;
  747.                         case 'mail':
  748.                             $finalDatas['clicks_cta_mail'] = $row['m_events'];
  749.                             break;
  750.                         case 'location':
  751.                             $finalDatas['clicks_cta_location'] = $row['m_events'];
  752.                             break;
  753.                         case 'rdv':
  754.                             $finalDatas['clicks_cta_rdv'] = $row['m_events'];
  755.                             break;
  756.                     }
  757.                 }
  758.             }
  759.         }
  760.         return $finalDatas;
  761.     }
  762.     /**
  763.      * Récupére le nombre de clic sur les réseaux sociaux
  764.      * @throws TransportExceptionInterface
  765.      * @throws ServerExceptionInterface
  766.      * @throws RedirectionExceptionInterface
  767.      * @throws DecodingExceptionInterface
  768.      * @throws ClientExceptionInterface
  769.      */
  770.     public function getAllClicksSocialMedia($pianoId$lang$magasin$beginDate null$endDate null): int
  771.     {
  772.         $nbClicks 0;
  773.         $dates = [
  774.             'start' => (!is_null($beginDate) ? $beginDate $this->beginDate),
  775.             'end' => (!is_null($endDate) ? $endDate $this->endDate)
  776.         ];
  777.         $postDatas = [
  778.             'columns' => [
  779.                 'event_name',
  780.                 'click_chapter1',
  781.                 'proprietary',
  782.                 'lang_version',
  783.                 'm_events'
  784.             ],
  785.             'sort' => [
  786.                 '-m_events'
  787.             ],
  788.             'filter' => [
  789.                 'property' => [
  790.                     '$AND' => [
  791.                         [
  792.                             'click_chapter1' => [
  793.                                 '$eq' => 'social_networks'
  794.                             ]
  795.                         ],
  796.                         [
  797.                             'proprietary' => [
  798.                                 '$eq' => $magasin
  799.                             ]
  800.                         ],
  801.                         [
  802.                             'lang_version' => [
  803.                                 '$eq' => $lang
  804.                             ]
  805.                         ]
  806.                     ]
  807.                 ]
  808.             ],
  809.             'space' => [
  810.                 's' => [
  811.                     intval($pianoId)
  812.                 ]
  813.             ],
  814.             'period' => [
  815.                 'p1' => [
  816.                     [
  817.                         'type' => 'D',
  818.                         'start' => $dates['start'],
  819.                         'end' => $dates['end']
  820.                     ]
  821.                 ]
  822.             ],
  823.             'max-results' => 50,
  824.             'page-num' => 1,
  825.             'options' => [
  826.                 'ignore_null_properties' => true
  827.             ]
  828.         ];
  829.         $response $this->getResponse($postDatas);
  830.         if ($response->getStatusCode() === 200) {
  831.             $datas $response->toArray();
  832.             foreach ($datas['DataFeed']['Rows'] as $row) {
  833.                 $nbClicks $row['m_events'];
  834.             }
  835.         }
  836.         return $nbClicks;
  837.     }
  838.     /**
  839.      * @throws TransportExceptionInterface
  840.      */
  841.     private function getResponse($datas): ResponseInterface
  842.     {
  843.         return $this->httpClient->request('POST'$this->urlAt, [
  844.             'headers' => [
  845.                 'Content-Type' => 'application/json',
  846.                 'x-api-key' => $this->apiKey
  847.             ],
  848.             'body' => json_encode($datas)
  849.         ]);
  850.     }
  851. }