SDITools / adobeanalyticsr

R Client for Adobe Analytics API v2.0
Other
18 stars 9 forks source link

Error when building sequential segments #142

Open abidawson opened 2 years ago

abidawson commented 2 years ago

Hi there - thanks for your work on this package! I'm especially excited to see that you've exposed the ability to create segments via API and would love to see the capability to do calculated metrics as well.

I haven't been able to find examples for the segment-related functions in the docs yet (I assume you haven't gotten there) and I'm getting tripped up on creating sequential segments. I think there must be something wrong with my input below that's resulting in the error, maybe in what I'm supplying to the "sequences" argument of seg_build. If anyone can help I would much appreciate it!

Input:

#sequential segment
my_rule <- seg_rule(metric = "pageviews",
                    verb = "event-exists", 
                    validate = TRUE
)

my_rule_2 <- seg_rule(metric = "orders",
                      verb = "event-exists", 
                      validate = TRUE
)

my_sequence <- seg_seq(context = "visits",
                       rules = list(my_rule, my_rule_2),
                       sequence = "in_order")

seg_build(name = "Test Segment from API - Sequential",
          description = "pageviews exists then order exists",
          sequences = list(my_rule, my_rule_2, my_sequence),
          sequence_context = "visits",
          sequence = "in_order",
          context = "visitors",
          create_seg = TRUE
)

Output:

Error in handle_api_errors(resp = req, body = body) : 
  errorCode: invalid_data
errorDescription: Segment validation failed. HTTP 400 Bad Request - Segment validation failed, validation response was {"validator_version":"1.1.19","message":["Definition validation error"],"errors":[{"location":"container.pred.stream[0].pred","error":19,"message":"Invalid Sequence Implicit Context: must be \"visits\" or \"visitors\".","error-str":"InvalidSequenceImplicitContext"},{"location":"container.pred.stream[0].pred.stream","error":13,"message":"Empty Array: Empty arrays are not supported","error-str":"EmptyArray"},{"location":"container.pred.stream[1]","error":20,"message":"Invalid Sequence Stream: A sequence stream can only be calls to container(), sequence-and(), sequence-or(), time-restriction(), container-restriction(), dimension-restriction(), and exclude-next-checkpoint()","error-str":"InvalidSequenceStream"},{"location":"container.pred.stream[2]","error":20,"message":"Invalid Sequence Stream: A sequence stream can only be calls to contai
benrwoodard commented 2 years ago

Hey Abi, Yes, the documentation is still being worked on but hopefully, soon we will have some more information and demos available. Calculated metrics build functions are also in the works but still need a bit of work before they are ready to go.

Looks like there is something wrong with the seg_seq() function and maybe also in the seg_build() function. It's not populating the two rules in the final segment definition as it should. I'll look into it and hopefully get something working soon. Thanks for the clear example to work from.

benrwoodard commented 2 years ago

Hey Abi,

Just a quick bump here. I'm still working out the solution. The embarrassing truth is that I left out the option to build segments with metrics. I've almost got a working solution but it probably won't be ready until the end of next week.

abidawson commented 2 years ago

Hi Ben - no problem, thanks for the update. This isn't urgent for me, just excited to use the package and wanted to try a bunch of example use cases, so that timing is more than adequate for me.

benrwoodard commented 11 months ago

Hey Abi! I realize it's been about 18 months (where did the time go?) since I got back to you but I think I have it working now. I've got a few more tests to run and need to finish up a few more edits across some other package improvements before publishing to CRAN. Hopefully you haven't given up all hope yet! If you would like to give it a test on your side, let me know. Other than that, I'll make sure to reply when I publish the new updates to CRAN.

image