Set Up the Data Layer for Google Tag Manager
A data layer is a JavaScript object that passes information from your website to your Google Tag Manager (GTM) container. The Reddit tag uses this information to automatically populate event metadata and match keys.
You can use this setup when either the Reddit Pixel alone—or both the Reddit Pixel and Conversions API (CAPI)—are set up in GTM. When used together, the same data is shared across web and server events, helping improve conversion accuracy.
1. Add data layer code to your web page
Create a script to pass data to the data layer:
<script>
window.dataLayer = window.dataLayer || [];
</script>
2. Set up data layer variables
Add the event name and extra parameters that you’d like to pass to the data layer. We recommend that you:
- Pass email for better attribution
- Send conversion ID for proper event deduplication when using both Reddit Pixel and CAPI
- When sending Add to Cart or Purchase events, share product ID, name, and category.
Reference
Available parameters
Customer match keys, such as email and phone numbers, are automatically normalized and hashed using SHA-256. Learn more about hashing.
| Reddit parameter | Data layer parameter |
|---|---|
| Conversion event | event |
| Email address | user_data.email_address |
| Phone number | user_data.phone_number |
| Item count | ecommerce.items[].quantity |
| Value | ecommerce.items[].value |
| Currency | ecommerce.items[].currency |
| Products | |
Event values
| Conversion event | Value |
|---|---|
| Page Visit | ‘page_view’ |
| View Content | ‘view_item’ |
| Search | ‘search’ |
| Add To Cart | ‘add_to_cart’ |
| Add To Wishlist | ‘add_to_wishlist’ |
| Purchase | ‘purchase’ |
| Lead | ‘generate_lead’ |
| Sign Up | ‘sign_up’ |
Examples
Page Visit
dataLayer.push({
ecommerce: null
}); // Clear previous ecommerce object
dataLayer.push({
event: "page_view",
user_data: {
email_address: "alice@site.com",
phone_number: "+15554441234"
},
ecommerce: {
items: []
}
});
View Content
dataLayer.push({
ecommerce: null
}); // Clear previous ecommerce object
dataLayer.push({
event: "view_item",
user_data: {
email_address: "alice@site.com",
phone_number: "+15554441234"
},
ecommerce: {
items: [{
item_id: "abc123",
item_name: "Potato",
item_category: "Vegetable"
}]
}
});
Add to Cart
dataLayer.push({
ecommerce: null
}); // Clear previous ecommerce object
dataLayer.push({
event: "add_to_cart",
user_data: {
email_address: "alice@site.com",
phone_number: "+15554441234"
},
ecommerce: {
currency: "USD",
value: 100.00,
items: [{
item_id: "abc123",
item_name: "Potato",
item_category: "Vegetable",
quantity: 1,
price: 100.00
}]
}
});
Purchase
dataLayer.push({
ecommerce: null
}); // Clear previous ecommerce object
dataLayer.push({
event: "purchase",
user_data: {
email_address: "alice@site.com",
phone_number: "+15554441234"
},
ecommerce: {
value: 100.00,
currency: "USD",
items: [{
item_id: "abc123",
item_name: "Potato",
item_category: "Vegetable",
quantity: 2,
price: 50.00
}]
}
});
Learn more
In this section: Configure Signals > Third-party Integrations > Google Tag Manager