I am developing a new plugin. I created a new metric in the Archiver.php by aggregating data using the Db class, but my problem is that I want to create that metric using Segments defined by users. Is there a way to make this simple or do I have to create a different query for every existing segment?
I found this (Segment class):
$idSites = array(1,2,3);
$segmentStr = "browserCode==ff;countryCode==CA";
$segment = new Segment($segmentStr, $idSites);
$query = $segment->getSelectQuery(
$select = "table.col1, table2.col2",
$from = array("table", "table2"),
$where = "table.col3 = ?",
$bind = array(5),
$orderBy = "table.col1 DESC",
$groupBy = "table2.col2"
);
Db::fetchAll($query['sql'], $query['bind']);
But I still don’t see the benefit of using it instead of just writing my own query.
Do I have to write a different query for every segment to be able to create my new segmented metric?
And if a new segment is created, I would be forced to include a new query to support that segment?