Dotdigital Tag API methods

The following API methods are client-side functions which send user interaction data to a server.

Using the Dotdigital Tag, you can capture events such as page views, user logins, product browsing and cart updates, and access this data in both Dotdigital and Fresh Relevance accounts.

  • Purpose: These methods facilitate real-time data ingestion, supporting personalized marketing and analytics by mapping data to defined schemas.
  • Usage: They are called in JavaScript to track user actions and send data to a server endpoint.

Learn more about the Dotdigital Tag.


Key events

Event type

Method

Description

Page change

window.ddg.track(data)

Tracks page visits.

User identification

window.ddg.identify({...})

Identifies a user with specific attributes such as email, mobile number, and name.

Product browse

window.ddg.productBrowse( {...} )

Tracks product browsing events with detailed product information.

Product list

window.ddg.productList({data})

Tracks a list of products viewed by the contact.

Cart update

window.ddg.cartUpdate({...})

Updates cart information with detailed cart and product data.

Checkout

window.ddg.checkout({...})

Tracks checkout events.

When used, the cart Insight data’s CartPhase in Dotdigital is set to ORDER_CHECKOUT .

Purchase complete

window.ddg.purchaseComplete({...})

Tracks purchase completion events.

When used, the cart Insight data’s CartPhase in Dotdigital is set to ORDER_COMPLETE .

Custom event

window.ddg.event("eventName",{...})

Sends custom events defined by you.*

*Custom events in Dotdigital are only available in our CXDP account package.


Method reference

ddg.track(pageData)

Tracks page visits.

pageData object

NameTypeDescription
urlstringThe full URL of the visited page.
titlestringThe title of the visited page.
localTimedate | stringThe local time of the page visit in either the ISO8601 string or date format. Defaults to now if not provided.

Example

window.ddg.track({
    url: "https://example.com/checkout",
		title: "Cart checkout",
		localTime: "2025-11-25T13:37:57Z"
});

ddg.identify(identityDetails)

Identifies a user with specific attributes such as email, mobile number, and name.

identityDetails object

NameTypeDescription
email (required)stringUser's email address, note at least one identifier (email or mobile) is required
mobileNumberstringUser's mobile number in E.164 format
firstNamestringUser's first name. Note, only made available in Fresh Relevance
lastNamestringUser's last name. Note, only made available in Fresh Relevance
fullNamestringUser's full name. Note, only made available in Fresh Relevance

Example

window.ddg.identify({
  email: "[email protected]",
  mobileNumber: "+447911123456",
  firstName: "Jane",
  lastName: "Doe",
  fullName: "Jane Doe"
});

ddg.getTrackedId()

Returns the Dotdigital Contact ID for known users of undefined if an anonymous user.

Example

var contactId = window.ddg.getTrackedId();

ddg.productBrowse(product)

Tracks product browsing events with detailed product information.

product object

Name

Type

Description

productId

string

Unique identifier for the product.

sku

string

Stock Keeping Unit.

name

string

Name of the product.

url

string

Full URL of the product page.

imageUrl

string

Full URL of the product thumbnail image.

imageThumbnailUrl

string

Full URL of the product thumbnail image.

price

number

Price of the product.

salePrice

number

Sale price of the product.

currency

string

Currency code in ISO 4217 formatCurrency code (ISO 4217)

priceInclTax

number

Price including tax.

salePriceInclTax

number

Sale price including tax.

status

string

Status of the product.

stock

number

Stock of the product.

description

string

Description of the product.

categories

array[category]

Categories the product belongs to.

extraData

object

Additional data related to the product.

lang

string

Language code.

brand

string

Brand of the product.

variantId

string

Unique identifier of the variant.

variants

array[variant]

Array of product variants.

variant object

Property nameTypeDescription
idstring
urlstring
namestring
stocknumber
imagestring

category object

A product category can be either a string or { categoryName: string; groupName: string; }

Property nameData type
categoryNamestring
groupNamestring

Example

window.ddg.productBrowse({  
    productId: 'uniqueproductid',  
    name: 'name',  
    price: 1.12,  
    imageThumbnailUrl: 'http://www.image.com/thumbnail.jpg',  
    imageUrl: 'http://www.image.com/image.jpg',  
    priceInclTax: 1.35,  
    salePrice: 3.2,  
    salePriceInclTax: 3.5,  
    sku: 'sku-123',  
    status: 'status',  
    stock: 1,  
    url: 'http://product.com/product.html',  
    brand: 'brand name',  
    lang: 'language',  
    categories: [  
        'category 1',  
        { categoryName: 'category 3', groupName: 'category group' }],  
    currency: 'currency',  
    description: 'description',  
    extraData: {  
        'string value': 'hello world',  
        'int value': 1542,  
        'float value': 1.12,  
        'boolean value': true  
    },  
    variantId: 'var1',  
    variants: [  
        {  
            id: 'var1',  
            image: 'http://www.image.com/image_a.jpg',  
            name: 'variation 1',  
            stock: 1,  
            url: 'http://product.com/product_variation1.html'  
        },  
        {  
            id: 'var2',  
            image: 'http://www.image.com/image_b.jpg',  
            name: 'variation 2',  
            stock: 1,  
            url: 'http://product.com/product_variation2.html'  
        }  
    ]  
});

ddg.productList([product])

Tracks a list of products viewed by the contact.

Parameters

An array of product objects.

Example

window.ddg.productList(  
    [  
        {  
            brand: 'brand name',  
            categories: [  
                'category 1',  
                { categoryName: 'category 3', groupName: 'category group' }],  
            currency: 'currency',  
            description: 'description',  
            extraData: {  
                'string value': 'hello world',  
                'int value': 1542,  
                'float value': 1.12,  
                'boolean value': true  
            },  
            imageThumbnailUrl: 'http://www.image.com/thumbnail.jpg',  
            imageUrl: 'http://www.image.com/image.jpg',  
            lang: 'language',  
            name: 'product 1',  
            price: 1.12,  
            priceInclTax: 1.35,  
            productId: 'product id',  
            salePrice: 3.2,  
            salePriceInclTax: 3.5,  
            sku: 'sku-123',  
            status: 'status',  
            stock: 1,  
            url: 'http://product.com/product.html',  
            variantId: 'var1',  
            variants: [  
                {  
                    id: 'var1',  
                    image: 'http://www.image.com/image_a.jpg',  
                    name: 'variation 1',  
                    stock: 1,  
                    url: 'http://product.com/product_variation1.html'  
                },  
                {  
                    id: 'var2',  
                    image: 'http://www.image.com/image_b.jpg',  
                    name: 'variation 2',  
                    stock: 1,  
                    url: 'http://product.com/product_variation2.html'  
                }  
            ]  
        },  
        {  
            brand: 'brand name',  
            categories: [  
                'category 1',  
                { categoryName: 'category 3', groupName: 'category group' }],  
            currency: 'currency',  
            description: 'description',  
            extraData: {  
                'string value': 'hello world',  
                'int value': 1542,  
                'float value': 1.12,  
                'boolean value': true  
            },  
            imageThumbnailUrl: 'http://www.image.com/thumbnail.jpg',  
            imageUrl: 'http://www.image.com/image.jpg',  
            lang: 'language',  
            name: 'product 2',  
            price: 1.12,  
            priceInclTax: 1.35,  
            productId: 'product id 2',  
            salePrice: 3.2,  
            salePriceInclTax: 3.5,  
            sku: 'sku-123',  
            status: 'status',  
            stock: 1,  
            url: 'http://product.com/product.html',  
            variantId: 'var1',  
            variants: [  
                {  
                    id: 'var1',  
                    image: 'http://www.image.com/image_a.jpg',  
                    name: 'variation 1',  
                    stock: 1,  
                    url: 'http://product.com/product_variation1.html'  
                },  
                {  
                    id: 'var2',  
                    image: 'http://www.image.com/image_b.jpg',  
                    name: 'variation 2',  
                    stock: 1,  
                    url: 'http://product.com/product_variation2.html'  
                }  
            ]  
        }  
    ]  
);

ddg.cartUpdate(cartDetails)

cartDetails object

Name

Type

Description

cartId

string

Unique identifier for the cart

cartPhase

string

Status of the cart

currency

string

Currency code in ISO 4217 format

subtotal

number

Subtotal amount

shipping

number

Shipping cost

discountAmount

number

Discount amount

taxAmount

number

Tax amount

grandTotal

number

Grand total amount

cartUrl

string

URL of the cart page

products

array[cartProduct]

Cart product objects

*You can choose the value to send for cartPhase, but suggested values are ORDER_PENDING, ORDER_CHECKOUT, ORDER_COMPLETE, or CUSTOMER_LOGIN.

If no value is specified, then for ddg.cartUpdate we set cartPhase to ORDER_PENDING and for ddg.purchaseComplete we set it to ORDER_COMPLETE.

cartProduct object

Name

Type

Description

productId

string

Unique identifier for the product *

sku

string

Stock Keeping Unit.

name

string

Name of the product.

description

string

Description of the product.

categories

category | array[category ]

Categories the product belongs to.

extraData

object

Additional data related to the product.

unitPrice

number

Price per unit.

unitPriceInclTax

number

Price per unit including tax.

salePrice

number

Sale price .

salePriceInclTax

number

Sale price including tax.

quantity

number

Quantity of products added to cart.

totalPrice

number

Total price.

totalPriceInclTax

number

Total price including tax.

imageUrl

string

Full URL of the product thumbnail image.

productUrl

string

Full URL of the product page.

variantId

string

Unique identifier of the variant.

brand

string

Brand of the product.

*Only required for Fresh Relevance

Example

window.ddg.cartUpdate({
  cartId: "123ABCZZFSEFSEFESZZZZZee",
  currency: "USD",
  subtotal: 35.98,
  shipping: 8,
  discountAmount: 0,
  taxAmount: 0,
  grandTotal: 35.98,
  cartUrl: "https://www.example.com/checkout/cart",
  products: [
    {
      productId: 'uniqueproductid',
			sku: "576879",
      name: "Shirt",
      description: "A super great description of the product",
      category: "Shirts >> T-Shirts >> Blue",
      other: {"fieldName": "This can be a string or any value you like"},
      unitPrice: 11.99,
      salePrice: 11.99,
      quantity: 20,
      totalPrice: 23.98,
      imageUrl: "http://www.example.com/a/p/shirt.jpeg",
      productUrl: "http://www.example.com/index.php/shirt.html"
    }
  ]
});

ddg.checkout(cartDetails)

Tracks checkout events.

📘

When this method is used, the cartinsight's CartPhase in Dotdigital is set to ORDER_CHECKOUT .

You need to pass a cartDetails object that represents the cart being checked out.

Example

window.ddg.checkout({
  cartId: "123ABCZZFSEFSEFESZZZZZee",
  currency: "USD",
  subtotal: 35.98,
  shipping: 0,
  discountAmount: 0,
  taxAmount: 0,
  grandTotal: 35.98,
  cartUrl: "https://www.example.com/checkout/cart",
  products: [
    {
      productId: 'uniqueproductid',
			sku: "576879",
      name: "Shirt",
      description: "A super great description of the product",
      category: "Shirts >> T-Shirts >> Blue",
      other: {"fieldName": "This can be a string or any value you like"},
      unitPrice: 11.99,
      salePrice: 11.99,
      quantity: 20,
      totalPrice: 23.98,
      imageUrl: "http://www.my-website.com/a/p/shirt.jpeg",
      productUrl: "http://www.my-website.com/index.php/shirt.html"
    }
  ]
});

ddg.purchaseComplete(cartDetails)

Tracks purchase completion events.

📘

This method can be used to generate order Insight records in Dotdigital if you aren’t otherwise syncing orders into Dotdigital.

When this method is used, the cartinsight's CartPhase in Dotdigital is set to ORDER_COMPLETE .

Learn more in Add the Dotdigital Tag to your website: Advanced settings.

You need to pass a cartDetails object that represents the cart being completed.

Example

window.ddg.purchaseComplete({
  cartId: "123ABCZZFSEFSEFESZZZZZee",
  orderId: "45645",
  currency: "USD",
  subtotal: 35.98,
  shipping: 0,
  discountAmount: 0,
  taxAmount: 0,
  grandTotal: 35.98,
  cartUrl: "https://www.my-website.com/checkout/cart",
  products: [
    {
      productId: 'uniqueproductid',
			sku: "576879",
      name: "Shirt",
      description: "A super great description of the product",
      category: "Shirts >> T-Shirts >> Blue",
      other: {"fieldName": "This can be a string or any value you like"},
      unitPrice: 11.99,
      salePrice: 11.99,
      quantity: 20,
      totalPrice: 23.98,
      imageUrl: "http://www.my-website.com/a/p/shirt.jpeg",
      productUrl: "http://www.my-website.com/index.php/shirt.html"
    }
  ]
});

ddg.event(eventName, attributes)

Custom events in Dotdigital are only available in our CXDP account package.

Sends custom events defined by you. These are automatically added to an Insight data collection of the same name as your event name/type.

🚧

Ensure you use the same event name/type for events of the same type so that they are collated into the same Insight data collection for easy reference.

Parameters

NameTypeDescription
eventNamestringThe name/type of the event being tracked.
attributesobjectAn object containing any additional event attributes that may be useful.

Example

Raising custom events whenever a customer searches for a holiday destination in a website.

window.ddg.event("Search destination", {
  "query":"Bali",
  "travel_from_date" : "2025-07-03"
});

Result: Insight collection: Search_destination Insight collection type: event

Insight record:

{
  "id": "5dbe0b01-c0d0-423e-a457-5c9d49d6e5b6",
  "event": "Search destination",
  "created_date": "2025-05-13T14:07:30.64Z",
  "attributes": {
    "query": "Bali",
    "travel_from_date": "2025-07-03"
  }
}

ddg.setCookiesConsent(true|false)

This method is used to indicate whether the Dotdigital tag can save cookies to the browser or not. It should be used in conjunction with your cookie consent manager and called whenever the visitors permission to store cookies changes to ensure the Dotdigital Tag honors those settings correctly.

Parameters

A simple boolean value where:

  • true - Indicates that the Dotdigital Tag can save cookies.
  • false - Indicates that the Dotdigital Tag cannot save cookies.

Example

window.ddg.setCookiesConsent(true) // Cookies are allowed.
window.ddg.setCookiesConsent(false) // Cookies are not allowed.