Subscribe to events

Bronze Contributor
Bronze Contributor

Hi, 

Is there a way to listen to Tealium events? I want to be able with JS to subscribe to 'add to cart' and 'purchase' events and perform an action upon of it

3 REPLIES 3

Subscribe to events

Tealium Expert
Tealium Expert

Hi @DynamicYield 

I'm not sure there is such a thing as a "Tealium add to cart event".  The add to cart event would be triggered from the page (ie on a click of a button) or fired from the site code (ie the site JS might call utag.link() and pass a data object with event details directly). 

Can you give some more details about what you are trying to do?

One of my clients has a site that fires events from the page using 

$(window).trigger("eventName", dataObject)

and then I've added code to JS extensions to listen for these events and handle them in Tealium:

$(window).on("eventName", function(eventname, data) {
//manipulation of the data object
utag.link(data);
});

But this is handling site events, not Tealium events.

 

Subscribe to events

Bronze Contributor
Bronze Contributor

Thanks for your reply however I'm looking to subscribe to Tealium event.

$(window).on("utag.event.purchase", function(eventname, data) {
//manipulation of the data object
DY.API('event', {properties: data})l
});

Subscribe to events

Moderator
Moderator

As @BenStephenson said, the general use case is TiQ receiving tracking events from the page (and/or automatically triggering pageview events on load).  Those incoming "events" are then compared to Load Rules for Tags, which are fired if appropriate.  

The functionality implied by your snippet would be covered in the corresponding Tag Template and/or tag-scoped Extensions (to manipulate the data more manually, if needed).  Tags 'subscribe' to events based on their Load Rules inside TiQ.

I've never tried, but I don't see why I wouldn't be possible to set something custom up in TiQ to trigger window-level events for other code to listen for, if there were a compelling use case to keep tag-like code outside of TiQ.

But that's not available out-of-the-box, and I'd expect using a Tag to be the better option in nearly every case (for all the reasons it's useful to have all Tags in a single TMS, etc.).

Hope that helps?

Public