Skip to content

Possible race condition when dataTagGetData from 2 rapidly fired data layer events #28

@hugentobler

Description

@hugentobler

At the moment, when marking "add_data_layer" to true on the Data Tag, the following function is called in browser window to retrieve the latest dataLayer data. However, if one has 2 of the same event firing in rapid succession in the client, the Data Tag is always only able to grab the latest dataLayer data of the second event. Resulting in a race condition. Any suggestions on how to solve this? For now I must unpack the dataLayer data on the client-side and send it as an event or user property.

function dataTagGetData(containerId) {
    window.dataTagData = {
        document: {
            characterSet: window.document.characterSet,
        },
        innerWidth: window.innerWidth,
        innerHeight: window.innerHeight,
        screen: {
            width: window.screen.width,
            height: window.screen.height,
        },
        dataModel: window.google_tag_manager[containerId].dataLayer.get({
            split: function() { return []; }
        }),
    };

    return window.dataTagData;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions