Setup in Embedded App SDK code would like this based on the documentation:
ShopifyApp.ready(function(){
var shopifyQL = "SHOW count() FROM visits SINCE -2w UNTIL today";
var renderData = function(response) {
// do amazing things here
};
var handleError = function(response) {
// handle missing API errors here (missing scopes, back shopifyql, etc...)
};
ShopifyApp.Analytics.fetch({
query: shopifyQL,
success: renderData,
error: handleError
});
});
From the old Embedded App SDK documentation, it mentions that ShopifyApp.ready(fn) has " no equivalent method in Shopify App Bridge, as this functionality is no longer necessary."
I tried to migrate the code to use the Shopify App Bridge, however it did not work:
import createApp from '@shopify/app-bridge';
const app = createApp({
apiKey: '<api key>',
shopOrigin: '<origin>',
});
// This works
app.getState().then((state) => {
console.info('App State: %o', state);
});
// This doesn't work
app.Analytics.fetch({
query: 'SHOW count() FROM visits SINCE -2w UNTIL today',
success: () => { console.info('success'); },
error: () => { console.info('error'); },
});
Is it possible to use the Analytics API with the App Bridge? If not, what would be wrong with my syntax? Any documentation on this would be a big help
Just chiming in to say that at this time you cannot use the analytics API at the same time as App Bridge. We’re currently working on finding a path forward with handling the analytics API working with App Bridge.
To give you a straight update here, as of right now the Analytics API is still not supported directly by the App Bridge.
However this feature is supported through the backwards compatibility layer. So if you are looking to use this feature in your app, you can use the EASDK to write your code and then enable the App Bridge backward compatibility layer to kick in. That way you can still utilize the Analytics API and ShopiQL from your app. Read here for more details on the backward compatibility layer: https://shopify.dev/tools/app-bridge/migrating