Gatsby Custom Targeting

Hi Steve,

Is it possible to use custom targeting using gatsby and cookies?

I added 3 pages with similar urlPath and with different whatEverKey values. Then I tried adding this code below somewhere in my code but it’s not filtering my pages.

builder.setUserAttributes({
  userIsLoggedIn: cookies.get("userIsLoggedIn"),
  whatEverKey: cookies.get("whatEverKey"),
});

It always end up with the page that has no additional targeting aside from urlPath. When I added all 3 pages with a targeting whatEverKey, nothing is display. The graphql results returns empty.

Please enlighten me with this one.

Thanks,

Chester

hey @chesteralan - you absolutely can, but due to the static nature of Gatsby the cookie targeted values need to run in the browser only. So builder.setUserAttributes() won’t impact the GraphQL responses, but it can be used browser side, such as

function MyComponent() {
  const [section, setSection] = useState(null);

  useEffect(() => {
     builder.setUserAttributes(...)
     builder.get('section').promise().then(setSection)
  }, [])

  return section ? <BuilderComponent model="section" content={section} /> : null
}

Thank you much @steve ! I’ll it out.