Access to UTM campaign fields via API?

MrPunkin
Shopify Partner
87 0 42

Can someone tell me if I'm just missing somewhere we can retrieve the UTM Campaign, UTM Name, and UTM Source fields that you can download in reports via the API (GraphQL or REST)? I can't seem to find anything about it, but it seems like they should be available somewhere.

Replies 10 (10)
Alex
Shopify Staff
Shopify Staff
1561 81 321

Hey @MrPunkin.

 

You can access this information on a CustomerVisit via the Admin GraphQL API. This can be accessed through Order.CustomerJourney.Moment(CustomerVisit). A query for that would look like this:

 

query {
  orders(first:200) {
    edges {
      node {
        customerJourney {
          moments {
            ...on CustomerVisit {
              utmParameters {
                source
                campaign
                content
                medium
                term
              }
            }
          }
        }
      }
    }
  }
}

The above makes use of inline fragments, which you can learn more about here if that's unfamiliar to you.

Alex | 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 the Shopify Help Center or the Shopify Blog

MrPunkin
Shopify Partner
87 0 42

Alex,

 

Thanks for this info. I'll spend some time digging into this today.

Alex
Shopify Staff
Shopify Staff
1561 81 321

To get that data on a specific order, you can query that order directly:

 

{
  order(id: "gid://shopify/Order/5642150741") {
    id
    customerJourney {
      moments {
        ... on CustomerVisit {
          utmParameters {
            source
            campaign
            content
            medium
            term
          }
        }
      }
    }
  }
}

Let me know though if I'm misunderstanding your question.

 

Edit

 

Looks like you edited your post, I'll put this up regardless.

Alex | 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 the Shopify Help Center or the Shopify Blog

MrPunkin
Shopify Partner
87 0 42

I did, sorry. I didn't notice that all of this was nested under the orders data at first. This should be what I need, but I'll let you know if it isn't for some reason.

謝紹壯
New Member
4 0 0

excuse me:

How to get UTM parameters through rest admin API?

謝紹壯
New Member
4 0 0

I have been searching for rest admin API document for a long time, but I haven't found the appropriate interface to get the UTM parameters associated with the order.

How to get UTM parameters through rest admin API?

MrPunkin
Shopify Partner
87 0 42

Unfortunately I believe this is only available via the GraphQL API, and does not exist within the REST API. I had to implement the GraphQL API for my needs to track the UTM variables from the CustomerJourney object.

謝紹壯
New Member
4 0 0
There is a question.
Since the UTM parameter can be obtained in graphql API, indicating that the order is associated with this parameter, why not open it in the rest API?
bjxie
New Member
3 0 0

你解决了么,我也遇到了,这个两套api返回不一致很蛋疼啊

MrPunkin
Shopify Partner
87 0 42

I believe Shopify is moving towards exposing some data only via the GraphQL API. I believe this is mostly due to having their core API development moving forward clearly focused on GraphQL. I don't think they can't add it to REST, but rather that they simply wont.