javascriptgoogle-tag-managergoogle-analytics-4google-datalayer

How do I make sure my Select Content GA4 event doesn't remove the type and ID values?


I'm trying to set up the select_content event as laid out in the GA4 Recommended Events page.

However, my current organization wants to use the dataLayer syntax to push this event to GTM instead of gtag.js. The way I've set it up looks like this:

const dataLayerObjectToPush: {
    event: "select_content",
    content_type: "type_string",
    content_id: "id_string"
};

window.dataLayer = window.dataLayer || [];
window.dataLayer.push(dataLayerObjectToPush);

However, when I send it through to be processed through GTM, the content_type and content_id values get stripped. What's happening here, and how can I make sure those values don't get removed?


Solution

  • I found the solution: I needed to set up the appropriate variables in Google Tag Manager, and link them to my select_content event.