Adding custom attributes
This section describes the steps to add a custom attribute with the name category to the pageview event using Google Tag Manager (GTM).
Prerequisites and Assumptions
Before you proceed to add custom attribute to the pageview event, ensure that you fulfill the following prerequisites and assumptions.- Complete all the prerequisites for GTM Integration. For more information, see Prerequisites for GTM Integration.
- You must have one custom dimension available for Acoustic Personalization to send the category attribute data. Ensure that you have created a custom dimension field with a value dimension2 and with Hit scope in Google Analytics.
Step 1: Create a user-defined variable customAttributeDimensionVariable in Google Tag Manager
Variable Type: Data Layer Variable
Data Layer Variable Name: dimension2 [or dimensionN]
Data Layer Version: Version 2
Step 2: In your Google Analytics Settings variable GA-Id, set the references to custom variables
Note: Ensure that you use the Google Analytics settings variable GA-Id already
created before.
Custom Dimensions > Index: 2, Dimension
Value: {{customAttributeDimensionVariable}} Note: The values for
dimensions that are shown here are only for illustrative purpose. You must use the Index and
Dimension Value according to your setup.
Step 3: Add the following code in the GTM tag of the customFunction of the
Step 5 of GTM Integration.
For more information, see GTM Integration
google_ubx.googleToUBXPageViewEvent.attributesMapper.push({ "googleName": "cd2", "ubxName": "category", "type": "string" });
Note: In this code snippet,
cd2 indicates dimension2. Use the index value as
applicable.Step 4:
- Method 1: Add the following code in the GTM tag of the
customFunctionfunction of Step 5 of GTM Integration topic. For more information, see GTM Integrationgoogle_tag_manager[{{Container ID}}].dataLayer.set('dimension2','<<comma-separated category values>>'); - Method 2: Add the following code in your HTML page or web page after the GTM code
snippet.
window.dataLayer.push({'dimension2' : '<<comma-separated category values>>'});