Learn business growth with Google Analytics 4 Forums Google Analytics 4 Improving GTM Data Layer by Clearing Previous Event Properties Reply To: Improving GTM Data Layer by Clearing Previous Event Properties

  • Lucas

    5 October 2022 at 11:36 pm

    In this scenario, it seems like old properties from your previous event are recurring because you’re not setting these properties as null when they’re not in use. What you can do is while sending the data object include all properties, but for the ones that are not being used, just assign them as null. So when you’re sending ‘Zack’ and ‘Ryder’, also send hobby and age as null.

    Also, you mentioned something about trying to reset through tag sequencing. The thing here is, you should call the reset after your event is pushed, not before. This way, the data you need doesn’t get wiped out prematurely.

    Real quick though, keep in mind that although tag sequencing could work, it might affect the state of your data layer.

    Now, if you can’t nullify fields from the frontend and still want to fix this using Google Tag Manager, you’ve got another option. This involves creating a custom JavaScript variable (CJS). Here, all your data layer variables go through this CJS variable. The function of this CJS variable would be to inspect what values each event has and pass them on as required. But remember, you’ll need to do this for each data layer field that you want to cleanse.