Hey team, we have the html sdk setup on our stagin...
# ask-questions
c
Hey team, we have the html sdk setup on our staging website. Trying to figure out how to pass datalayer name/value data to a growthbook attribute for targeting. I've already set the attribute "brand" in the growthbook app, and the data exists in the datalayer. When I put a test live I can also see growthback can pass data to the datalayer... just don't know how to make it go back growthbook. URL - https://mcstaging.fitmycar.com.au/ford/ranger/ute-2022-current/1375-4 console.log(_growthbook) - I use this to check attributes available for targeting chrome > dev tools > console "dataLayer" for datalayer values
r
Hi there! I understand you want to add brand as a custom attribute. Here is an example:
Copy code
<script>
window.growthbook­_config = window.growthbook­_config || {};
window.growthbook­_config.attributes = {
    brand: "xyz",
    otherCustomAttribute: 12,
}
</script>
You'll want to add this before the other GrowthBook code. Learn more in the docs: https://docs.growthbook.io/lib/script-tag#adding-custom-attributes
c
Hi Ryan I thought the existing values in the datalayer were immediately available for use "In addition, if you use Google Tag Manager, any variables you set in your Data Layer will also be set here and available for targeting." https://docs.growthbook.io/lib/script-tag#targeting-attributes
Trying avoid additional dev costs. Seemed to track (in my mind at least) that if growthbook could automatically pass the experiment id to the datalayer that it could also pull data from the datalayer as well??
r
Gotcha! I looked at the code on your site and how our code works. It looks like brand is part of a custom event in GA, but we strip out custom events, which is why you aren't seeing it. Currently, then, you'd need to add that data in a different way in your app, as it won't be included automatically. How are you constructing that event for GA?