Trying to get analytics information through API

Highlighted
Shopify Partner
3 0 4

I'm attempting to programmatically retrieve the number of visitors I've had from instagram on my shop. The information is easily accessible through the analytics dashboard in shopify, but I can't seem to get the information through either the graphql api or the rest api.  

 

From what I can tell, the graphql api does not have this information at all, but the rest API should.  My problem is that I cannot figure out how to get the analytics token that is required to send with the request.  

 

This is the specific request I need, which I got from the chrome dev tools of https://my-shop.myshopify.com/admin/reports/sessions_by_referrer?startDate=2019-03-29&endDate=2019-0...:

 

 

https://analytics.shopify.com/queries?beta=true

token: HOW_DO_I_GET_THIS?
q[]: SHOW+total_visitors+AS+%22total_visitors...
source: shopify-reports

I have copied this request to postman and it works fine, as long as I use the token that I got from the chrome dev tools request.  I just need to know how to get the analytics token programatically.  Thanks!

 

3 Likes
Highlighted
New Member
2 0 1

I think if you have a private app it should work with your secret. However, I am not sure. Please try and give updates!

1 Like
Highlighted
New Member
2 0 2

hi,did you resolved the problem , i have the same question. can you tell me how to acquire the token  ? thanks in advance.

1 Like
Highlighted
Shopify Partner
3 0 4

I never did resolve the issue.  From what I can tell, in order to get a token you have to be subscribed to the Shopify Plus plan (the $300/month plan), so perhaps that is why I wasn't able to get a token.

 

If you go to the analytics page in the admin console and inspect the network with your browsers dev tools you can see the token.  You can then take that token and make your own requests with it.  However, I don't know of a way to get that token without a hack like this.

 

It's really frustrating, and I ended up just moving on from the project I was trying to complete.

1 Like
Highlighted
New Member
2 0 2

ok. thanks for your reply ! If i find a way, i will reply .

1 Like
Highlighted
Excursionist
30 0 0

Hi, I have also the same problem?Anybody resolve this or not?Please tell me


@demonhuntervn wrote:

ok. thanks for your reply ! If i find a way, i will reply  

0 Likes
Highlighted
Shopify Partner
8 0 2

Im trying to do this too, We have tried the digging out tokens from a browser session hack which works just as we want.

But we want to do it without the hack. 

 

We have managed to dig out the data from the graph ql api, but its a bit of a pain...

0 Likes
Highlighted
New Member
6 0 0

Hey, could you elaborate on how you were able to dig out analytics data from the graphql?

 

Any help would be much appreciated. Thank you.

0 Likes
Highlighted
Shopify Partner
8 0 2

Hi, 

We have managed to get number of visitors from different sources using this graphql  "edge": https://shopify.dev/docs/admin-api/graphql/reference/object/order/customerjourney?api[version]=2020-...

The firstVisit/lastVisit holds information about where the customer comes from. BUT this is of course not the all the visits, only the visits that generated an order. We have not found a way to track all the visits through the API. I guess you can use google analytics for that or similar. 

Anyway, using the "analytics" API that the admin dashboard is using would solve a lot of our problems. Thats the numbers that our clients usually compare the data we can get from the graph QL with. And its hard to get those numbers to match...

 

Does that answer your question?

 

/Antonio at Funnel

0 Likes