Linking Segment with SliceMachine

Hi all! I'm building a marketplace platform using Expo/NextJS and react native. We're using Slicemachine to write how-to guides. I was wondering if anyone had any best practices for linking segment event tracking into Slicemachine. For example, it'd be great to track button clicks inside a Slice for a specific page.

Since each slice is a reusable component, it does not know the context of the page it is in. Would this data be within the Slice component? Or would it be best to go an alternative route with NextJS router functions?

Hey @mona,

This is an interesting use case! Thanks for raising it :slight_smile:

Personally, I have no experience with Segment, and I've never seen any guide for using Segment with Prismic. However, based on your description, I have one idea: the <SliceZone> component allows you to pass a context prop to deliver data to your Slices. That could allow you to pass the page-level data that you need down to each Slice to track your button clicks.

<SliceZone 
  slices={document.data.body}
  components={components}
  context={pagePath}
/>

Let me know if that helps.

In any case, if you figure this out please let us know how you did it! I'm guessing that other Prismic developers will have similar questions.

Sam