Setting up Analytics API: "ShopifyApp is undefined"

susa1234
New Member
2 0 0

I've been following this tutorial in order to access store data from the analytics API: https://shopify.dev/tutorials/get-store-metrics-with-analytics-api 

 

(1) The "Analytics Api" is bundled with "Embedded App SDK". "Embedded App SDK" is deprecated. I am asked to use "Shopify App Bridge" instead -  Is there a way to use "Analytics Api" with "Shopify App Bridge" or should I implement "Embedded App SDK" nevertheless?

 

(2) Following the documentation on "Embedded App SDK" I added the according code to the <head> of my file:

 

<script src="https://cdn.shopify.com/s/assets/external/app.js"></script>
<script type="text/javascript">{
ShopifyApp.init({
apiKey: 'my-private-api-key',
shopOrigin: 'https://my-dev-shop.myshopify.com',
debug: true
})}
</script>  
 
I keep receiving the error message "ReferenceError: ShopifyApp is not defined" - any idea why this is happening? I pretty much tried everything to resolve it.
 
Thanks
0 Likes
hannachen
Shopify Staff
Shopify Staff
49 8 14

Hi @susa1234 👋, apologies for the delayed response. Were you able to get it working eventually?

I tried the code snippet in a toy app, but didn't reproduce the error. Where are you seeing the message? Do you see the error inside the admin, or when you view the page outside of Shopify admin? Do you see the same error if you move the script tags outside of head, and into right before end of body?

For context, the analytics API is indeed not supported by App Bridge, so unfortunately, Embedded App SDK (EASDK) is the way to go.

0 Likes