Add custom attributes - GTM
Add a custom attribute with the name category to the pageview event using Google Tag Manager (GTM).
Before you begin:
- Configure GTM with Exchange prerequisites.
- Create a custom dimension field with a value dimension2 and with Hit scope in GA. One custom dimension for Personalization is required to send the category attribute data.
To add custom attributes, complete the following steps:
- Create a user-defined variable
customAttributeDimensionVariablein GTM.
- Variable Type: Data Layer Variable
- Data Layer Variable Name: dimension2 [or dimensionN]
- Data Layer Version: Version 2
-
In your GA Settings variable
GA-Id, set the references to custom variables. Use the GA settings variable GA-Id already created before.
Custom Dimensions > Index: 2,
Dimension Value:{{customAttributeDimensionVariable}} -
In the script execution code added to the GTM tag, add the following to the
customFunction.
In this code snippet, cd2 indicates dimension2. Use the index value as applicable.google_ubx.googleToUBXPageViewEvent.attributesMapper.push({ "googleName": "cd2", "ubxName": "category", "type": "string" }); -
Next, add the following code to the
customFunction.
google_tag_manager[{{Container ID}}].dataLayer.set('dimension2','COMMA-SEPARATED CATEGORY VALUES');
You can also add the following code to your HTML page or web page after the GTM code snippet.
window.dataLayer.push({'dimension2' : 'COMMA-SEPARATED CATEGORY VALUES'});Updated 12 days ago
