javascriptgoogle-tag-managergoogle-datalayer

Is it possible to get user data from dataLayer on GTM?


I'm new to Google Tag Manager – GTM. I have a webpage where Google Tag Manager scripts are embedded. I set several events which push objects to dataLayer as dataLayer.push({KEY: VALUE}). My question is how can I retrieve the data which added/pushed before.

For example, let's say there is a <button onclick="dataLayer.push({'item': 'shoes A'})">Purchase</button> on the e-commerce site and a user clicked the button to purchase the item. Then, if the user comes back to the page on the next day, how can I get the user's previously bought item information from dataLayer, which is {'item': 'shoes A'}. I might misunderstand how the dataLayer works but wondering whether it is possible. Or, dataLayer is a variable just for passing information to Google Tag Manager? Not for retrieve data?

Sorry for the basic question but could not figure out well by looking at tutorial sites. If any advice, that would be very appreciated.


Solution

  • As said in the comments:

    The data layer is purely used for adding to Google's data to build the statistics panels in the Google Analytics pages.
    Google Analytics is not a relational database. You cannot query individual data sets back.

    If you want to keep track what things you have pushed you should keep a permanent record (maybe generated from the cart contents then?) in database or session variables.

    Google's dataLayer documentation for developers:
    https://developers.google.com/tag-manager/devguide