> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Product interactions dataset

> LayersQL Product interactions dataset reference for finding products that shoppers view, add to cart, or buy together with a given product.

* **Label:** Product interactions
* **Description:** Product pairs that shoppers interact with together, such as products viewed in the same session or bought in the same order. Each row pairs an anchor product with a related product for one interaction type and rolling time window.
* **Default group key:** `related_product`

## How this dataset differs

Product interactions are rolling snapshots, not dated events, so a few rules apply:

* **Filter by anchor product.** Every query must limit `product` with `=` or `IN`, and every `OR` branch must do the same. You can look up at most 20 anchor products per query.
* **Pick a window with `time_window`.** Snapshots cover the last `30d` or `90d`. Not every interaction type has both windows. `SINCE`, `UNTIL`, and `DURING` don't change the results.
* **No comparisons or trends.** `COMPARE TO` and `TIMESERIES` are not supported.
* **No shared session dimensions.** The [personalization dimensions](https://docs.uselayers.com/platform/layersql/datasets.md#personalization-dimensions-all-datasets) are not available on this dataset.

## Metrics

* **interaction\_count (events)**
  * Observed interactions for the pair.
  * Example: SHOW interaction\_count
* **confidence\_score (rate)**
  * Pair interactions divided by observations of the anchor product. Higher values mean shoppers who interact with the anchor more often interact with the related product too.
  * Example: SHOW confidence\_score
* **lift\_score**
  * Conservative, prior-adjusted lift for the pair. Higher values mean the pairing is stronger than each product's popularity alone would suggest.
  * Example: SHOW lift\_score
* **anchor\_count (events)**
  * Observations of the anchor product.
  * Example: SHOW anchor\_count

## Dimensions

* **recipe**
  * Interaction type: `customers_also_viewed`, `frequently_bought_together`, `customers_also_added_to_cart`, `viewed_then_bought`, `viewed_then_viewed`, or `customers_also_bought`.
* **preferred\_recipe**
  * Set to `TRUE` to include `customers_also_bought` only for anchors that have no `frequently_bought_together` rows in the same window. This matches the **Also bought** list in the dashboard.
* **time\_window**
  * Rolling window: `30d` or `90d`.
* **product**
  * Anchor Shopify product ID.
* **related\_product**
  * Related Shopify product ID.
* **same\_leaf\_category**
  * Whether the two products share the same product taxonomy category.
* **title**, **product\_type**, **available**
  * Title, product type, and availability of the related product.
* **product.\<attribute>**, **related\_product.\<attribute>**
  * Filter or group by a product attribute on either side of the pair, for example `related_product.color`.

## Examples

Top products viewed alongside one product in the last 30 days:

```sql theme={null}
FROM product_interactions
SHOW confidence_score, interaction_count
WHERE product = 7712345678901 AND recipe = 'customers_also_viewed' AND time_window = '30d'
GROUP BY ONLY TOP 5 related_product
```

What shoppers buy with either of two products, using the dashboard's bought-together fallback:

```sql theme={null}
FROM product_interactions
SHOW confidence_score, lift_score
WHERE product IN (7712345678901, 7712345678902)
  AND recipe IN ('frequently_bought_together', 'customers_also_bought')
  AND preferred_recipe = TRUE
  AND time_window = '90d'
GROUP BY related_product
SEGMENT BY recipe
```

Related products in a different color than the anchor:

```sql theme={null}
FROM product_interactions
SHOW interaction_count
WHERE product = 7712345678901 AND time_window = '30d' AND related_product.color != 'red'
GROUP BY related_product
```

## Next steps

* [LayersQL syntax](https://docs.uselayers.com/platform/layersql/syntax.md)
* [Performance panel](https://docs.uselayers.com/platform/metrics.md#performance-panel)
