Search code examples
shopifyshopify-appshopify-template

Shopify App: Any event for detecting change of theme or make theme sections persist even after theme changes?


I've created a shopify app which adds a new theme section to active theme when it is installed. Now I am concerned that if the shopify store user changed their store's theme then my theme section changes will get removed.
Is there a way to persist my theme section changes. If not, can I listen to an event/webhook from shopify which will inform me of the change in theme?


Solution

  • There are webhooks for themes/update and themes/publish. You might try monitoring for publish events with theme_id or name properties that don't match your expected theme and issue warning notifications about those section data going away.

    This is an example response from the docs:

    {
      "id": null,
      "name": "Comfort",
      "created_at": "2021-04-01T14:58:14-04:00",
      "updated_at": "2021-04-01T14:58:14-04:00",
      "role": "main",
      "theme_store_id": 1234,
      "previewable": true,
      "processing": false
    }