The FunnelEnvy platform natively sends audience, campaign and related data and events into the browser data layer. These can be used to create Variables and Triggers in Google Tag Manager, or handled programmatically in the browser.

For programatic integration FunnelEnvy includes a data layer helper and exposes a function to allow developers to handle messages.

To add a listener use the following structure after the window.funnelEnvy object has been instantiated:

window.funnelEnvy.addListener(eventName, function(model, message) {
/* your code to handle messages and access the data layer model*/
});

More information about listeners can be found in the data layer helper repository README on Github: https://github.com/google/data-layer-helper

Example: Running code after the FunnelEnvy snippet has completed

You might want to run some code after the FunnelEnvy snippet has finished evaluating audiences and campaigns. To do this you'll listen for the backstage.completed event as in the following example:

window.funnelEnvy.addListener("backstage.completed", function(model, message) {
/* your code to handle messages and access the data layer model*/
console.log("FunnelEnvy completed!");
});

Note that for this event (backstage.completed) the model will be an empty object, however for other events (e.g. backstage.audiencesUpdated or backstage.activeCampaign ) the model will include a payload of data.

Also note that the backstage.completed event is guaranteed to fire after any synchronously variation code has rendered, however if your variation code is asynchronous then rendering may complete after this event has been dispatched.

A reference for the FunnelEnvy snippet events can be found in this knowledge base article.

Did this answer your question?