SlicingDice Documentation

SlicingDice API Docs

Welcome to the SlicingDice API documentation. You'll find comprehensive guides and documentation to help you start working with SlicingDice as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Documentation

Count events


A SlicingDice count events query is equivalent to a SQL query like this:

SELECT COUNT(*) 
FROM   UserEvents 
WHERE  UserEvents.Actions = 'Add to Cart' 
       AND UserEvents.Timestamp BETWEEN 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-15d" %}' 
           AND 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-1d" %}'; 

Query purpose

You should use count events to know the number of times some data was inserted for event columns in a particular table.

Count event queries are ideal to answer this kind of questions:

  • How many times the event visited-page for the actions column happened in the last 24 hours?
  • How many times the value for the purchases-values column was greater-than 1000 and happened between {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}?

Query endpoint

In order to make a count events query, you simply need to send a POST request to https://api.slicingdice.com/v1/query/count/events with an array of JSON object (or a single JSON object) of queries identified by unique names, each containing a list of conditions.

Pro Tip

Remember that you can also use the /test endpoint https://api.slicingdice.com/v1/test/insert to make data insertions and https://api.slicingdice.com/v1/test/query/count/events to query before inserting real data to your production database.

Consider generating a free demo API key for yourself to use in all examples below, as indicated on the try before you buy page.


Query syntax and structure

The between predicate is required in the conditions, along with one of the following:

Also, note it is not possible to use boolean operators, such as not, and and or in count events queries.

In this query below we will count how many times the event visited-page for the actions column happened between {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}.

curl -X POST https://api.slicingdice.com/v1/query/count/event \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
    {
        "query-name": "visited-page-events",
        "query": [
            {
                "actions": {
                    "equals": "visited-page",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "query": [
            {
                "actions": {
                    "equals": "visited-page",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "visited-page-events"
    }
]

print(slicingdice.count_event(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("actions", new JSONObject()
                        .put("equals", "visited-page")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))
            .put("query-name", "visited-page-events"));
        JSONObject result = slicingdice.countEvent(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "query" => [
            {
                "actions" => {
                    "equals" => "visited-page",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name" => "visited-page-events"
    }
]

puts slicingdice.count_event(query_data)

const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const queryData = [
    {
        "query": [
            {
                "actions": {
                    "equals": "visited-page",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "visited-page-events"
    }
];

slicingdice.countEvent(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$queryData = array(
    array(
        "query" => array(
            array(
                "actions" => array(
                    "equals" => "visited-page",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        ),
        "query-name" => "visited-page-events"
    )
);

print_r($slicingdice->countEvent($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"actions", new Dictionary<string, dynamic>{
                                {"equals", "visited-page"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "visited-page-events"}
                }
            };

            var result = slicingdice.CountEvent(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "query": []interface{}{
                map[string]interface{}{
                    "actions": map[string]interface{}{
                        "equals": "visited-page",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
            "query-name": "visited-page-events",
        },
    }

    fmt.Println(slicingdice.CountEvent(queryData))
}

The API response for this query above will be in the format below:

{
    "status": "success",
    "result": {
        "visited-page-events": 1
    },
    "took": 0.103
}

Let's understand each component of the API response:

  • status - Indicating whether the request was successfully processed or not.
  • result - Query name (visited-page-events) and total number of events that matches all query conditions.
  • took - Time spent processing this request, in seconds.

Query operators, predicates and parameters

Supported predicates

This is the list of supported predicates for the count events query.

equals

Usage example: How many events happened where the action was equals to Jeff?

gt or greater-than

Usage example: How many events happened where the purchase-value was greater than 50?"

gte or greater-than-or-equal

Usage example: How many events happened where the purchase-value was greater than or equal to 18?".

lt or less-than

Usage example: How many events happened where the purchase-value was less than 50?"

lte or less-than-or-equal

Usage example: How many events happened where the purchase-value was less than or equal to 21?".

between (required)

Usage example: How many events happened where the action was equal to "Pay Now" between the dates {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}?

Supported parameters

bypass-cache (optional)

Usage example: Boolean value defining to bypass or not the cache mechanism.

Use "bypass-cache": true to ignore cached data. bypass-cache is false by default, meaning that all queries will be cached.

query-name (optional)

You can send multiple queries in a same request, so when you send more than one query, these queries must be identified by unique names.

table (optional)

In which the query should be performed over.

If you do not provide a value to table, the query will be performed over the default table.

Supported operators

Currently, count events queries do not support any operators.


Query examples

Find below many count events queries, using multiple data types, operators, predicates and parameters.

Ready-to-use examples

All SlicingDice's clients/SDK have many ready-to-use examples on their Github repositories.
Check the our client/SDK page to know more.

Complete example

Below you can find a complete count events query request example, using most of the supported predicates.

Example:

  1. How many purchases happened where the value was greater than $1,000?
  2. How many clicks did the "Pay Now" button had?
 curl -X POST https://api.slicingdice.com/v1/query/count/event \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
    {
        "query-name": "expense-purchases",
        "query": [
            {
                "purchase-value": {
                    "greater-than": 1000,
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "bypass-cache": false
    },
    {
        "query-name": "clicks-on-pay-now",
        "query": [
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "bypass-cache": false
    }
]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "query": [
            {
                "purchase-value": {
                    "greater-than": 1000,
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "expense-purchases",
        "bypass-cache": False
    }, 
    {
        "query": [
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "clicks-on-pay-now",
        "bypass-cache": False
    }
]

print(slicingdice.count_event(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("purchase-value", new JSONObject()
                        .put("greater-than", 1000)
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))
            .put("query-name", "expense-purchases")
            .put("bypass-cache", false))
        .put(new JSONObject()
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("clicks", new JSONObject()
                        .put("equals", "Pay Now")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))
            .put("query-name", "clicks-on-pay-now")
            .put("bypass-cache", false));
        JSONObject result = slicingdice.countEvent(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "query" => [
            {
                "purchase-value" => {
                    "greater-than" => 1000,
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name" => "expense-purchases",
        "bypass-cache" => false
    }, 
    {
        "query" => [
            {
                "clicks" => {
                    "equals" => "Pay Now",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name" => "clicks-on-pay-now",
        "bypass-cache" => false
    }
]

puts slicingdice.count_event(query_data)

const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const queryData = [
    {
        "query": [
            {
                "purchase-value": {
                    "greater-than": 1000,
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "expense-purchases",
        "bypass-cache": false
    }, 
    {
        "query": [
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "clicks-on-pay-now",
        "bypass-cache": false
    }
];

slicingdice.countEvent(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$queryData = array(
    array(
        "query" => array(
            array(
                "purchase-value" => array(
                    "greater-than" => 1000,
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        ),
        "query-name" => "expense-purchases",
        "bypass-cache" => false
    ), 
    array(
        "query" => array(
            array(
                "clicks" => array(
                    "equals" => "Pay Now",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        ),
        "query-name" => "clicks-on-pay-now",
        "bypass-cache" => false
    )
);

print_r($slicingdice->countEvent($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"purchase-value", new Dictionary<string, dynamic>{
                                {"greater-than", 1000},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "expense-purchases"},
                    {"bypass-cache", false}
                }, 
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"clicks", new Dictionary<string, dynamic>{
                                {"equals", "Pay Now"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "clicks-on-pay-now"},
                    {"bypass-cache", false}
                }
            };

            var result = slicingdice.CountEvent(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "query": []interface{}{
                map[string]interface{}{
                    "purchase-value": map[string]interface{}{
                        "greater-than": 1000,
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
            "query-name": "expense-purchases",
            "bypass-cache": false,
        },
        map[string]interface{}{
            "query": []interface{}{
                map[string]interface{}{
                    "clicks": map[string]interface{}{
                        "equals": "Pay Now",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
            "query-name": "clicks-on-pay-now",
            "bypass-cache": false,
        },
    }

    fmt.Println(slicingdice.CountEvent(queryData))
}

Not contains example

Example: How many pages that not contains "visit" was visited?

 curl -X POST https://api.slicingdice.com/v1/query/count/event \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
    {
        "query-name": "visited-pages-not-contains-visit",
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "bypass-cache": false
    }
]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "visited-pages-not-contains-visit",
        "bypass-cache": False
    }
]

print(slicingdice.count_event(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("visited-page-events", new JSONObject()
                        .put("not-contains", "visit")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))
            .put("query-name", "visited-pages-not-contains-visit")
            .put("bypass-cache", false));
        JSONObject result = slicingdice.countEvent(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "query" => [
            {
                "visited-page-events" => {
                    "not-contains" => "visit",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name" => "visited-pages-not-contains-visit",
        "bypass-cache" => false
    }
]

puts slicingdice.count_event(query_data)
const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const queryData = [
    {
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "query-name": "visited-pages-not-contains-visit",
        "bypass-cache": false
    }
];

slicingdice.countEvent(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$queryData = array(
    array(
        "query" => array(
            array(
                "visited-page-events" => array(
                    "not-contains" => "visit",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        ),
        "query-name" => "visited-pages-not-contains-visit",
        "bypass-cache" => false
    )
);

print_r($slicingdice->countEvent($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"visited-page-events", new Dictionary<string, dynamic>{
                                {"not-contains", "visit"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "visited-pages-not-contains-visit"},
                    {"bypass-cache", false}
                }
            };

            var result = slicingdice.CountEvent(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "query": []interface{}{
                map[string]interface{}{
                    "visited-page-events": map[string]interface{}{
                        "not-contains": "visit",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
            "query-name": "visited-pages-not-contains-visit",
            "bypass-cache": false,
        },
    }

    fmt.Println(slicingdice.CountEvent(queryData))
}

Filtered count events

Example: How many pages that not contains "visit" was visited by someone that have 21 years old or that the name starts with the "j" letter?

 curl -X POST https://api.slicingdice.com/v1/query/count/event \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
    {
        "filter": [
            {
                "age": {
                    "equals": 21
                }
            },
            "or",
            {
                "name": {
                    "starts-with": "j"
                }
            }
        ],
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "table": "users",
        "bypass-cache": false
    }
]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "filter": [
            {
                "age": {
                    "equals": 21
                }
            },
            "or",
            {
                "name": {
                    "starts-with": "j"
                }
            }
        ],
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "table": "users",
        "bypass-cache": False
    }
]

print(slicingdice.count_event(query_data))
import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("filter", new JSONArray()
                .put(new JSONObject()
                    .put("age", new JSONObject()
                        .put("equals", 21)))
                .put("or")
                .put(new JSONObject()
                    .put("name", new JSONObject()
                        .put("starts-with", "j"))))
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("visited-page-events", new JSONObject()
                        .put("not-contains", "visit")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))
            .put("query-name", "visited-pages-not-contains-visit")
            .put("bypass-cache", false));
        JSONObject result = slicingdice.countEvent(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "filter" => [
            {
                "age" => {
                    "equals" => 21
                }
            },
            "or",
            {
                "name" => {
                    "starts-with" => "j"
                }
            }
        ],
        "query" => [
            {
                "visited-page-events" => {
                    "not-contains" => "visit",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "table" => "users",
        "bypass-cache" => false
    }
]

puts slicingdice.count_event(query_data)
const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const queryData = [
    {
        "filter": [
            {
                "age": {
                    "equals": 21
                }
            },
            "or",
            {
                "name": {
                    "starts-with": "j"
                }
            }
        ],
        "query": [
            {
                "visited-page-events": {
                    "not-contains": "visit",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ],
        "table": "users",
        "bypass-cache": false
    }
];

slicingdice.countEvent(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$queryData = array(
    array(
        "filter" => array(
            array(
                "age" => array(
                    "equals" => 21
                )
            ),
            "or",
            array(
                "name" => array(
                    "starts-with" => "j"
                )
            )
        ),
        "query" => array(
            array(
                "visited-page-events" => array(
                    "not-contains" => "visit",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        ),
        "query-name" => "visited-pages-not-contains-visit",
        "bypass-cache" => false
    )
);

print_r($slicingdice->countEvent($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"filter", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"age", new Dictionary<string, dynamic>{
                                {"equals", 21}
                            }}
                        },
                        "or",
                        new Dictionary<string, dynamic>{
                            {"name", new Dictionary<string, dynamic>{
                                {"starts-with", "j"}
                            }}
                        }
                    }},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"visited-page-events", new Dictionary<string, dynamic>{
                                {"not-contains", "visit"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "visited-pages-not-contains-visit"},
                    {"bypass-cache", false}
                }
            };

            var result = slicingdice.CountEvent(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "filter": []interface{}{
                map[string]interface{}{
                    "age": map[string]interface{}{
                        "equals": 21,
                    },
                },
                "or",
                map[string]interface{}{
                  "name": map[string]interface{}{
                      "starts-with": "j",
                  },
                },
            },
            "query": []interface{}{
                map[string]interface{}{
                    "visited-page-events": map[string]interface{}{
                        "not-contains": "visit",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
            "query-name": "visited-pages-not-contains-visit",
            "bypass-cache": false,
        },
    }

    fmt.Println(slicingdice.CountEvent(queryData))
}

What's Next

Aggregations

Count events