How to detect if an app embed block is activated

How to detect if an app embed block is activated

GuillaumeFg
Shopify Partner
4 0 2

Hi! 

 

I am currently developing a Shopify app which creates an App embed block the user can activate or not. 

 

I would like to display if the user has already activated the embed block in my app but I don't find any API for this purpose. 

 

Is there a way to perform this?

 

Thanks! 

Replies 6 (6)

Liam
Shopify Staff
2862 313 816

Hi GuillaumeFg,

 

I totally see how it would be helpful to reflect on your apps' UI when the embed block is active - I've connected with our internal devs to see if this is possible. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

GuillaumeFg
Shopify Partner
4 0 2

Hello @Liam, thank you very much !

Liam
Shopify Staff
2862 313 816

Hi again Guillaume,

 

The product team got back to me and while Shopify does not support this at the moment, we're aiming to allow this functionality in future API versions. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Hujjat
Shopify Partner
10 1 4

Hey @Liam & @GuillaumeFg !

Based on Shopify documentation, this should be possible here

I needed this for my app so I did some investigation on how I can detect if app embed is added by user or not. 

Here is what I have found using Remix. 

In your loader function, first find the active theme ID, then read the settings_data.json file. The app embed data will be saved in this file when user enable it. 

`

const activeTheme = await admin.rest.resources.Theme.find({
session: session,
role: 'main',
})

const settings_data = await admin.rest.resources.Asset.all({
session: session,
theme_id: activeTheme.id,
asset: {"key": "config/settings_data.json"},
});`

It will return a json format. 
`

{
"current": {
"sections": {
...
},
"content_for_index": [

],
"blocks": {
"17878678986028907411": {
"type": "shopify:\/\/apps\/faceforms-better-pop-ups\/blocks\/app-embed\/f2173231-e611-461d-884b-bd8e6cc2ded4",
"disabled": false,
"settings": {
...
}
}
}
}
}

`
You can look for your own app embed data if exist in this json file. 

"<block_unique_ID>": {
"type:": "<partner_name>:\/\/apps\/<app_name>\/blocks\/<block_name>\/<unique_ID>"

It it exist and enabled you can find out. 


I hope it helps other too 🙂 

Thank you!
Hujjat Asghari | Director at Codeinspire.io

We custom Shopify themes and apps


Our apps:


CodeInspire Accessibility Tool
Echo: Checkout Personalisation

movsumov
Shopify Partner
76 4 25

Hey @Hujjat thanks for reply, I see asset api is marked as deprecated. Did you find any other way for verification?

movsumov
Shopify Partner
76 4 25

After checking docs carefully I see reading is not a problem so we can use this method 🙏