Personalization SDK: Dotdigital Tag API methods

🚧

Public preview

This feature is currently in preview and may be subject to short notice changes or improvements. If you're interested in joining the preview, contact your Customer Success representative.

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

These methods facilitate real-time data ingestion, supporting personalized marketing and analytics by mapping data to defined schemas.

They are called in JavaScript to track user actions and send data to a server endpoint.


Key events

Event typeMethodDescription
Set configurationwindow.ddg.configuration(data)

Sets site brand, language, and currency. Can optionally pass an existing session ID to Personalization.

Also sets cartDelay and programID for Dotdigital Marketing abandoned cart enrolments.

Page changewindow.ddg.track(data)

Tracks page visits.

Certain page types have more specific calls which are preferred. Learn more in the section Page-specific calls.

User identificationwindow.ddg.identify({...})Identifies a user with specific attributes such as email, mobile number, and name.
Product browsewindow.ddg.productBrowse({...} )Tracks product browsing events with detailed product information.
Product listwindow.ddg.productList({data})Tracks a list of products viewed by the contact.
Cart updatewindow.ddg.cartUpdate({...})Updates cart information with detailed cart and product data.
Checkoutwindow.ddg.checkout({...})

Tracks checkout events.

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

Purchase completewindow.ddg.purchaseComplete({...})

Tracks purchase completion events.

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

Custom eventwindow.ddg.event("eventName",{...})Sends custom events defined by you.*

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


Method reference

ddg.configuration(data)

Sets siteBrand, and language and currency for the session. Can also be used to pass a session ID of your choosing to Dotdigital Personalization, for example, from your website backend or a server-side integration. Also sets cartDelay and programID for Dotdigital Marketing abandoned cart enrolments, if required.

You can either call the method once at the beginning of a browsing session, then only call it again if any of the details change, or you can call the method on every page load, as you prefer.

NameTypeDescriptionRequired
marketing>cartDelaynumberNumber in minutes after a cart abandonment that user’s are enrolled in the abandoned cart program.No
marketing>programIDstringID of the abandoned cart program in Dotdigital Marketing.No
personalization>siteBrandstringThe Personalization siteBrand for the session.Yes
personalization>sessionIDstringExisting ID for the session passed from another system or site backend.No
site>languagestringThe site language for the user.Yes*
site>currencystringThe site currency.Yes*

*These values must be consistent with other values in the product collection to avoid creating duplicate product records.

Personalization session ID

sessionID allows you to pass in your own session identifier from your site backend, another system, or a server-side integration and have the Personalization SDK reference that identifier when passing activity into Dotdigital Personalization.

When provided, sessionID is automatically included on each subsequent call for the session. sessionID is passed in addition to standard Dotdigital system identifiers used by the SDK. If no value is passed for sessionID then the SDK manages it's own session ID.

You should set sessionID as early as possible so that the as much activity as possible can be attributed to it, but the value can b set at whatever point in the session it becomes available.

Example

window.ddg.configuration({
    marketing: {
        cartDelay: 30,
        programId: 12345
     },
    personalization: {        
        siteBrand: "US",
        sessionID: "session ID 123",
    },
    site: {
        language: "EN",
        currency: "USD"
    }
});

ddg.track(pageData)

Tracks page visits.

📘

Some page types have page-specific calls which should be used in place of ddg.track. Learn more.

pageData object

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

The type of the visited webpage.

Certain page types have more specific calls which should be used in place of ddg.track.

These calls send the relevant pageType automatically. Learn more in the section Page-specific calls.

Yes
extraDataobjectAdditional data related to the session.No

Example

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

*pageType can be one of 12 pre-defined page types, represented by a specific integer.

Any page that doesn’t match with these pre-defined types must be classified as Other (0). If pageType is omitted or an unsupported integer is provided, the pageType is automatically classified as Other.

Page typeRepresentative integer
Other0
Home_Page1
Product_Browse2
Product_List3
Cart4
Checkout5
Purchase_Complete6
Login7
Login_Complete8
Register9
Register_Complete10
Account11
Newsletter12

Page-specific calls

The following calls should be used for each of the specified pages of your site, in place of ddg.track.

🚧

Do not duplicate events

If you’re using one of the below page-specific calls, you must not fire a ddg.track call on the same page.

MethodPageType setExample
ddg.homepage(data)PAGE_TYPE_HOME_PAGE (1)Homepage visits
ddg.cart(data)PAGE_TYPE_CART (4)Cart page views
ddg.login(data)PAGE_TYPE_LOGIN (7)Login page views
ddg.loginComplete(data)PAGE_TYPE_LOGIN_COMPLETE (8)Successful logins
ddg.register(data)PAGE_TYPE_REGISTER (9)Registration page views
ddg.registerComplete(data)PAGE_TYPE_REGISTER_COMPLETE (10)Successful registrations
ddg.accountEdit(data)PAGE_TYPE_ACCOUNT (11)Account edit page views
ddg.newsletterEdit(data)PAGE_TYPE_NEWSLETTER (12)Newsletter subscription page views

Parameters

Each of the above accept an optional data object with the same fields as ddg.track(), except pageType, which is set automatically:


{
    url: string,           // Required - Page URL
    title: string,         // Required - Page title
    localTime?: Date | string,  // Optional - Local time
    extraData?: object,    // Optional - Additional data
}

ddg.identify(identityDetails)

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

identityDetails object

NameTypeDescriptionRequired
emailstring

User's email address.

At least one identifier (email or mobile number) is required.

Yes
If mobileNumber is not provided.
mobileNumberstring

User's mobile number in E.164 format.

At least one identifier (email or mobile number) is required.

Yes
If email is not provided.
firstNamestringUser's first name.No
lastNamestringUser's last name.No
fullNamestringUser's full name.No
customerIdstring

Unique identifier for the customer.

This value maps to the CID field in Personalization, but is not automatically mapped to a custom ID field in Marketing. The value is stored is webInsight records in Marketing.

No

Example

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

ddg.getTrackedId()

Returns the Dotdigital Marketing Contact ID for known users, or undefined if an anonymous user.

Example

var contactId = window.ddg.getTrackedId();

ddg.productBrowse(product)

Tracks product browsing events with detailed product information.

product object

NameTypeDescriptionRequired
productIdstringUnique identifier for the product.Yes
skustringStock Keeping Unit.Yes
namestringName of the product.Yes
urlstringFull URL of the product page.Yes
imageUrlstringFull URL of the product thumbnail image.Yes
imageThumbnailUrlstringFull URL of the product thumbnail image.Yes
pricenumberPrice of the product.Yes
salePricenumberSale price of the product.No
currencystringCurrency code in ISO 4217 formatYes*
priceInclTaxnumberPrice including tax.No
salePriceInclTaxnumberSale price including tax.No
statusstringStatus of the product.No
stocknumberStock of the product.No
descriptionstringDescription of the product.No
categoriesarray[category]Categories the product belongs to.No, but recommended
personalization>siteBrandstringThe Dotdigital Personalization siteBrand for the product.No
siteBrand must be set in the configuration call. If siteBrand is set at the product level, this takes precedence.
languagestringLanguage code in ISO 639 format.No*
variantIdstringUnique identifier of the variant.No, but recommended
variantsarray[variant]Array of product variants.No, but recommended
optionsobjectAdditional product-related data specific to the customer. Persists only for the session.No

*If lang, currency , and sbr are included in your product sync to Personalization, these details must also be passed through the Dotdigital Tag to ensure the product records can be matched.

variant object

Property nameTypeRequired
idstringYes
urlstringYes
namestringYes
stocknumberYes
imagestringYes
imageThumbnailUrlstringNo
pricenumberNo
priceInclTaxnumberNo
skustringNo
currencystringNo
descriptionstringNo
salePricenumberNo
salePriceInclTaxnumberNo
categoriesarray[category]No
extraDataobjectNo
languagestringNo
statusstringNo
stocknumberNo

category object

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

Property nameData typeRequired
categoryNamestringYes
groupNamestringYes
replaceBooleanNo, but recommended
If not provided, default is false.

Replace property behavior

replace = true
Existing data for that tag name is replaced. This is useful if you want to update incorrect data.

replace = false
Existing data for that tag name is not replaced. This allows you to append additional tag names.

Example

window.ddg.productBrowse({  
    productId: 'uniqueproductid',  
    name: 'name', 
    options: {
      “Option 1”: 5,
      “Option 2”: “Sam”
    }, 
    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',  
    language: 'language',  
    categories: [  
        'category 1',  
        { categoryName: 'category 3', groupName: 'category group', replace: true }],  
    currency: 'currency',  
    description: 'description',  
    extraData: {  
        'string value': 'hello world',  
        'int value': 1542,  
        'float value': 1.12,  
        'boolean value': true  
    },  
		personalization: {        
        siteBrand: "US"
    },
    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',
            imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
            price: 1.65,
            sku: 'sku-234',
            currency: 'currency',
            description: 'description',
            salePrice: 1.5,
            categories: [
                'category 1',  
                { categoryName: 'category 3', groupName: 'category group', replace: true }],
            extraData: {  
                'string value': 'hello world',  
                'float value': 1.12,
                'boolean value': true
            },
            language: 'language',
            status: 'status',
            stock: 1,
            salePriceInclTax: 1.63
        },  
        {  
            id: 'var2',  
            image: 'http://www.image.com/image_b.jpg',  
            name: 'variation 2',  
            stock: 1,
            url: 'http://product.com/product_variation2.html',
            imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
            price: 1.65,
            sku: 'sku-234',
            currency: 'currency',
            description: 'description',
            salePrice: 1.5,
            categories: [
                'category 1',  
                { categoryName: 'category 3', groupName: 'category group', replace: true }],
            extraData: {  
                'string value': 'hello world',  
                'float value': 1.12,
                'boolean value': true
            },
            language: 'language',
            status: 'status',
            stock: 1,
            salePriceInclTax: 1.63
        }  
    ]  
});

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', replace:false }],  
            currency: 'currency',  
            description: 'description',  
            extraData: {  
                'string value': 'hello world',  
                'int value': 1542,  
                'float value': 1.12,  
                'boolean value': true  
            },
            personalization: {        
                 siteBrand: "US"
            },
            imageThumbnailUrl: 'http://www.image.com/thumbnail.jpg',  
            imageUrl: 'http://www.image.com/image.jpg',  
            language: 'language',
            name: 'product 1',
            options: {
               “Option 1”: 5,
               “Option 2”: “Sam”
            }, 
            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',
                    imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
                    price: 1.65,
                    sku: 'sku-234',
                    currency: 'currency',
                    description: 'description',
                    salePrice: 1.5,
                    categories: [
                        'category 1',  
                        { categoryName: 'category 3', groupName: 'category group', replace: true }],
                    extraData: {  
                        'string value': 'hello world',  
                        'float value': 1.12,
                        'boolean value': true
                    },
                    language: 'language',
                    status: 'status',
                    stock: 1,
                    salePriceInclTax: 1.63
                 },  
                 {  
                    id: 'var2',  
                    image: 'http://www.image.com/image_b.jpg',  
                    name: 'variation 2',  
                    stock: 1,
                    url: 'http://product.com/product_variation2.html',
                    imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
                    price: 1.65,
                    sku: 'sku-234',
                    currency: 'currency',
                    description: 'description',
                    salePrice: 1.5,
                    categories: [
                        'category 1',  
                        { categoryName: 'category 3', groupName: 'category group', replace: true }],
                    extraData: {  
                        'string value': 'hello world',  
                        'float value': 1.12,
                        'boolean value': true
                    },
                    language: 'language',
                    status: 'status',
                    stock: 1,
                    salePriceInclTax: 1.63
                }  
            ]  
        },  
        {  
            brand: 'brand name',  
            categories: [  
                'category 1',  
                { categoryName: 'category 3', groupName: 'category group', replace:false }],  
            currency: 'currency',  
            description: 'description',  
            extraData: {  
                'string value': 'hello world',  
                'int value': 1542,  
                'float value': 1.12,  
                'boolean value': true  
            },
            personalization: {
                 siteBrand: "US"
            },
            imageThumbnailUrl: 'http://www.image.com/thumbnail.jpg',  
            imageUrl: 'http://www.image.com/image.jpg',  
            language: 'language',  
            name: 'product 2',
            options: {
               “Option 1”: 5,
               “Option 2”: “Sam”
            }, 
            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',
                    imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
                    price: 1.65,
                    sku: 'sku-234',
                    currency: 'currency',
                    description: 'description',
                    salePrice: 1.5,
                    categories: [
                        'category 1',  
                        { categoryName: 'category 3', groupName: 'category group', replace: true }],
                    extraData: {  
                        'string value': 'hello world',  
                        'float value': 1.12,
                        'boolean value': true
                    },
                    language: 'language',
                    status: 'status',
                    stock: 1,
                    salePriceInclTax: 1.63
               },  
               {  
                    id: 'var2',  
                    image: 'http://www.image.com/image_b.jpg',  
                    name: 'variation 2',  
                    stock: 1,
                    url: 'http://product.com/product_variation2.html',
                    imageThumbnailUrl: 'http://www.image.com/image_b.jpg',
                    price: 1.65,
                    sku: 'sku-234',
                    currency: 'currency',
                    description: 'description',
                    salePrice: 1.5,
                    categories: [
                        'category 1',  
                        { categoryName: 'category 3', groupName: 'category group', replace: true }],
                    extraData: {  
                        'string value': 'hello world',  
                        'float value': 1.12,
                        'boolean value': true
                    },
                    language: 'language',
                    status: 'status',
                    stock: 1,
                    salePriceInclTax: 1.63
                }  
            ]  
        }  
    ]  
);

ddg.cartUpdate(cartDetails)

cartDetails object

📘

The cartDetails object can also be included with other methods, and follows the same structure as detailed below.

NameTypeDescriptionRequired
cartIdstringUnique identifier for the cartYes
cartPhasestringStatus of the cartYes, but is automatically set based on method*
Ignored if passed to purchaseComplete().
currencystringCurrency code in ISO 4217 formatYes
subtotalnumberSubtotal amountYes
shippingnumberShipping costNo
discountAmountnumberDiscount amountNo
taxAmountnumberTax amountNo
grandTotalnumberGrand total amountYes
cartUrlstringURL of the cart pageYes
productsarray[cartProduct]Cart product objectsYes
extraDataobjectAdditional data related to the cart.No

*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

NameTypeDescriptionRequired
productIdstringUnique identifier for the productYes
skustringStock Keeping Unit.Yes
namestringName of the product.Yes
descriptionstringDescription of the product.No
extraDataobjectAdditional data related to the product.No
personalization>siteBrandstringThe Dotdigital Personalization siteBrand for the product.No
siteBrand must be set in the configuration call. If siteBrand is set at the product level, this takes precedence.
optionsobjectAdditional product-related data specific to the customer. Persists only for the session.No
unitPricenumberPrice per unit.Yes
unitPriceInclTaxnumberPrice per unit including tax.No
salePricenumberSale price .No
salePriceInclTaxnumberSale price including tax.No
quantitynumberQuantity of products added to cart.Yes
totalPricenumberTotal price.No
totalPriceInclTaxnumberTotal price including tax.No
imageUrlstringFull URL of the product thumbnail image.Yes
productUrlstringFull URL of the product page.Yes
variantIdstringUnique identifier of the variant.No, but recommended

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",
      options: {
            “Option 1”: 5,
            “Option 2”: “Sam”
      }, 
      description: "A super great description of the product",
      categories: ["Shirts", "T-Shirts", "Blue"],
      extraData: {"fieldName": "This can be a string or any value you like"},
      personalization: {
             siteBrand: "US"
      },
      price: 11.99,
      salePrice: 11.99,
      quantity: 20,
      totalPrice: 23.98,
      imageUrl: "http://www.example.com/a/p/shirt.jpeg",
      url: "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 Marketing 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",
      options: {
           “Option 1”: 5,
           “Option 2”: “Sam”
      }, 
      description: "A super great description of the product",
      categories: ["Shirts", "T-Shirts", "Blue"],
      extraData: {"fieldName": "This can be a string or any value you like"},
      personalization: {
            siteBrand: "US"
      },
      unitPrice: 11.99,
      salePrice: 11.99,
      quantity: 20,
      totalPrice: 23.98,
      imageUrl: "http://www.my-website.com/a/p/shirt.jpeg",
      url: "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 Marketing if you aren’t otherwise syncing orders into Marketing.

When this method is used, the cartinsight's CartPhase in Marketing is set to ORDER_COMPLETE .
Learn more in Set up the Dotdigital Tag: Advanced settings.

Unlike cartUpdate and checkout, purchaseComplete takes a wrapping object containing an orderId and a nested cart object.

purchaseDetails object

NameTypeDescriptionRequired
orderIdstringUnique identifier for the completed order.Yes
cartcartDetailsThe cart that was purchased.Yes

Example

window.ddg.purchaseComplete({
  orderId: "45645",
  cart: {
    cartId: "123ABCZZFSEFSEFESZZZZZee",
    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",
        options: {
            “Option 1”: 5,
            “Option 2”: “Sam”
        }, 
        description: "A super great description of the product",
        categories: ["Shirts", "T-Shirts", "Blue"],
        extraData: {"fieldName": "This can be a string or any value you like"},
        personalization: {
            siteBrand: "US"
        },
        price: 11.99,
        salePrice: 11.99,
        quantity: 20,
        totalPrice: 23.98,
        imageUrl: "http://www.my-website.com/a/p/shirt.jpeg",
        url: "http://www.my-website.com/index.php/shirt.html"
      }
    ]
  }
});

ddg.event(eventName, attributes)

📘

Custom events are only available to Dotdigital Marketing accounts on the CXDP 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

NameTypeDescriptionRequired
namestringThe name/type of the event being tracked.Yes
dataobjectAn object containing any additional event attributes that may be useful.Yes
timelineSummarystringString value, to appear on the Single customer view timeline.No

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 visitor’s 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.


Did this page help you?