webPixelCreate
Requires access scope. Also: The app requires read_customer_events access scope and user access permission.
Activate a web pixel extension by creating a web pixel record on the store where you installed your app.
When you run the mutation, Shopify validates it
against the settings definition in
shopify.extension.toml
. If the settings
input field doesn't match
the schema that you defined, then the mutation fails. Learn how to
define web pixel settings.
Arguments
- Anchor to webPixelweb•
Pixel WebPixel requiredInput! The web pixel settings in JSON format.
Anchor to WebPixelCreatePayload returnsWebPixelCreatePayload returns
- Anchor to userErrorsuser•
Errors [ErrorsWeb non-nullPixel User Error!]! The list of errors that occurred from executing the mutation.
- Anchor to webPixelweb•
Pixel The created web pixel settings.
- Create a web pixel
- Creating a web pixel with invalid settings returns an error
- webPixelCreate reference
Examples
mutation webPixelCreate($webPixel: WebPixelInput!) {
webPixelCreate(webPixel: $webPixel) {
userErrors {
field
message
code
}
webPixel {
id
settings
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation webPixelCreate($webPixel: WebPixelInput!) { webPixelCreate(webPixel: $webPixel) { userErrors { field message code } webPixel { id settings } } }",
"variables": {
"webPixel": {
"settings": {
"trackingId": "GA-TRACKING-ID-123"
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation webPixelCreate($webPixel: WebPixelInput!) {
webPixelCreate(webPixel: $webPixel) {
userErrors {
field
message
code
}
webPixel {
id
settings
}
}
}`,
{
variables: {
"webPixel": {
"settings": {
"trackingId": "GA-TRACKING-ID-123"
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation webPixelCreate($webPixel: WebPixelInput!) {
webPixelCreate(webPixel: $webPixel) {
userErrors {
field
message
code
}
webPixel {
id
settings
}
}
}`,
"variables": {
"webPixel": {
"settings": {
"trackingId": "GA-TRACKING-ID-123"
}
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation webPixelCreate($webPixel: WebPixelInput!) {
webPixelCreate(webPixel: $webPixel) {
userErrors {
field
message
code
}
webPixel {
id
settings
}
}
}
QUERY
variables = {
"webPixel": {
"settings": {
"trackingId": "GA-TRACKING-ID-123"
}
}
}
response = client.query(query: query, variables: variables)