<?php
phpinfo();
die;
//getDatas('https://api.adjust.com/kpis/v1/9z4r8gsp7k00/cohorts?start_date=2023-11-02&end_date=2023-11-02&grouping=networks,campaigns,countries,os_names&kpis=retained_users,paying_users,revenue_total&user_token=Tha-k75HDFTdG9WE_s58&attribution_type=click&cohort_period_filter=0,1,2,6,14,29,59,89,119&reattributed=all');
//getDatas('https://api.adjust.com/kpis/v1/9z4r8gsp7k00/cohorts?start_date=2023-11-02&end_date=2023-11-02&grouping=networks,campaigns,countries,os_names&kpis=retained_users,paying_users,revenue_total&user_token=Tha-k75HDFTdG9WE_s58&attribution_type=click&cohort_period_filter=0,1,2,6,14,29,59,89,119&reattributed=false');


function getDatas($url){
    $str = file_get_contents($url);
    $arr = json_decode($str, true);
    $install = 0;
    foreach ($arr['result_set']['networks'] as $network){
        if($network['token'] != '12v8vi0')continue;
        foreach ($network['campaigns'] as $campaign){
            foreach ($campaign['countries'] as $country){
                foreach ($country['os_names'] as $name){
//                    $install += $name['periods'][1]['kpi_values'][0];
                    $install += $name['kpi_values'][1];
                }
            }
        }
    }
    var_dump($install);
}

getDatas('https://api.adjust.com/kpis/v1/9z4r8gsp7k00?start_date=2023-11-02&end_date=2023-11-02&grouping=networks,campaigns,countries,os_names&kpis=daus,installs,revenue&user_token=Tha-k75HDFTdG9WE_s58&attribution_type=all&reattributed=all');
getDatas('https://api.adjust.com/kpis/v1/9z4r8gsp7k00?start_date=2023-11-02&end_date=2023-11-02&grouping=networks,campaigns,countries,os_names&kpis=daus,installs,revenue&user_token=Tha-k75HDFTdG9WE_s58&attribution_type=all&reattributed=false');