Adobe-Marketing-Cloud / marketing-cloud-php-sdk

PHP Library for the Adobe Digital Marketing API
MIT License
35 stars 32 forks source link

Possible to dynamically create new segment in API call? #10

Open laurenford2 opened 9 years ago

laurenford2 commented 9 years ago

Is it possible to dynamically create a new segment within the API call? Any info on how to do this is much appreciated! Thanks.

miguelfrmn commented 9 years ago

Try with this: https://marketing.adobe.com/developer/documentation/segments-1-4/r-save

laurenford2 commented 9 years ago

@bshaffer

I was able to successfully create inline segments for "selected" values (found the documentation for creating inline segments). However, I am still having problems creating inline segments for classification keyword searches.

The code below returns data, but it does not match the data in what I believe is an analogous report in SiteCatalyst.

The SiteCatalyst segment I am comparing this to is a visit-level segment, defined as evarXX contains 'abcdef'. I am pairing it with the 'Visits' metric.

Where am I going wrong?

AdobeDigitalMarketing_Autoloader::register();
$adm = new AdobeDigitalMarketing_Client();
$adm->getHttpClient()->setOption('api_version', '1.4');
$adm->authenticate($username, $secret);

$api = $adm->getSuiteApi();

$response = $api->post('Report.Queue', array('reportDescription' => array(
    'reportSuiteID' => 'xxxxx', 
    'dateFrom' => date($start_date),
    'dateTo' => date($end_date),
    'dateGranularity' => 'day', 
    'metrics'  => array(
        array('id' => 'visits'), 
    ),
    'segments' => array(
            array(
                'element' => 'evarXX',
                'classification' => 'classificationXX',
                'search' => array('type' => 'AND', 'keywords' => array('abcdef'))
                )
     ),
)));
bshaffer commented 9 years ago

your code looks perfect. The Sitecatalyst data is being segmented in a slightly different way, that could account for small differences in the returned data. If the differences are substantial, I would try (as mentioned by @miguelxt) to save the segment and use the segment ID rather than the inline segment.

laurenford2 commented 9 years ago

@bshaffer The difference is substantial. I'm using this API call as part of an automated dashboard which allows others to pull Omniture data without actually using Ad Hoc, so the inline segmentation portion is crucial to the purpose of the dashboard. Any idea why there are differences in the data? I'd like to better understand the cause.

miguelfrmn commented 9 years ago

I'm not sure where the difference may be, but you could try the following:

$response = $api->post('Report.Queue', array('reportDescription' => array(
    ...
    'segments' => array(
            array(
                'element' => 'evarXX',
                'classification' => 'classificationXX',
                'selected' => array('abcdef')
                )
     ),
)));
$response = $api->post('Report.Queue', array('reportDescription' => array(
   ...
    'elements' => array(
            array(
                'id' => 'evarXX',
                'search' => array('type' => 'AND', 'keywords' => array('abcdef'))
               // Or
               // 'selected' => array('abcdef')
                )
     ),
)));
laurenford2 commented 9 years ago

Thanks for the suggestion Miguel. I tried the element key approach, but that did not work. I receive the same result no matter which key I search for. The "selected" approach works but the segment I'm trying to create must be a "contains" rather than an "equals" segment.

Inline segmentation works fine for most keyword values I search for. It seems like there is only one particular value for which the API data does not match the data in Ad Hoc.

Any idea at all why this would happen? Other suggestions for troubleshooting?

laurenford2 commented 9 years ago

@bshaffer @miguelxt A colleague of mine tried this in python, and found that specifying the top option at 50,000 (to show 50K results) solved the problem. Is it possible to do this in Php?

Here's the python code:


elements = suite.report.range('2015-02-02', days=7, granularity='day') \
                .element(element="evarXX", search={"type": "AND", "keywords": ["abcdef"]}, top=50000).run()
bshaffer commented 9 years ago

Wow, interesting... yes, top would be defined in your report description like so:

$response = $api->post('Report.Queue', array('reportDescription' => array(
    ...
    'elements' => array(
            array(
                'top' => 50000,
                'id' => 'evarXX',
                'search' => array('type' => 'AND', 'keywords' => array('abcdef'))
            )
     ),
)));
laurenford2 commented 9 years ago

@bshaffer is it possible to specify the 'top' parameter in the inline segment array itself? For example, will this work? In this case I am not specifying an element, so this is an overtime report.

$response = $api->post('Report.Queue', array('reportDescription' => array(
...

    'segments' => array(
            array(
                'element' => 'evarXX',
                'top' => 50000,
                'classification' => 'classificationXX',
                'search' => array('type' => 'AND', 'keywords' => array('abcdef'))
                )
     ),
)));
bshaffer commented 9 years ago

No, the inline segments does not support the top parameter, as it would not make sense in that context. top limits the number of rows returned, and segments are filters, and so do not return rows.

laurenford2 commented 9 years ago

@bshaffer Ok, that makes sense. I have one more question for you.

I ran the code below, which returns the results array with breakdowns by day and by element. From this output, I can see that not all possible elements that match my search criteria (in the inline segment) are being returned. The array returned from this code has only 13 elements. When I run the code that searches for keyword within element but does not include inline segmentation (from your first comment today) the results array contains 63 elements, and the data matches what I see in Ad Hoc.

Is there a way, using inline segmentation, to specify that the maximum number of elements be returned?

Thanks again for your help.


$response = $api->post('Report.Queue', array('reportDescription' => array(
    'reportSuiteID' => 'xxxxx',
    'dateFrom' => date($start_date),
    'dateTo' => date($end_date),
    'dateGranularity' => 'day',
    'metrics'  => array(
        array('id' => 'visits'), 
    ),
    'elements' => array(
        array(
          'id' => 'evarXX',
          'top' => 50000,
        )
    ),

    'segments' => array(
            array(
                'element' => 'evarXX',
                'classification' => 'classificationXX',
                'search' => array('type' => 'AND', 'keywords' => array('abcdef'))
                )
     ),
)));
bshaffer commented 9 years ago

The code I have listed does not include a classification. Your code does. The classification would change the entire result of the report - could this be your issue?

laurenford2 commented 9 years ago

@bshaffer I don't think classification is the issue. The classification and evar itself contain exactly the same data. Issue is that not all elements are being returned in the code above, even with the top specification. Seems like the segments array is overriding that somehow.

How can I make sure all elements are returned, even when I'm using only a segments array and not specifying an element? (element is only specified in segments array)

laurenford2 commented 9 years ago

@bshaffer @miguelxt any ideas on my question above?

laurenford2 commented 9 years ago

@bshaffer checking in again. Any idea why inline segmentation only returns data for a subset of all available elements? are you aware of any documentation on why this happens and if there's a way to avoid it? thanks!