Developer forum

Forum » Development » JS event for page load

JS event for page load

Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Are there any event listeners we can use to get info on a page load?

I saw there was a RapidoHook.contentLoaded() for Rapido, but it is not fireing on all pages/content.
basically we need to send a Google tag Manager event on all page loads, and would like to know if there is default functionality for this, or if we need to extend it.


Replies

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
This post has been marked as an answer

Hi Martin

Great question. My experience with Google tab Manager is a little limited. On Rapido, if the content is not loaded via Handlebars, then you should be able to use "DOMContentLoaded" event listener: 

document.addEventListener("DOMContentLoaded", function () { 
    //The Google Tag Manager stuff
}

If Handlebars is in use, then as you already know, we will need to listen for a custom event "contentLoaded" on the specific element that is Ajax based. On the Product page this could be an example: 

document.getElementById("PriceAndActions").addEventListener("contentLoaded", function (event) {
    //The Google Tag Manager stuff
}

I am not sure if this will solve all the situations related to Google Tag manager. But if you have a more specific case, then maybe we can find a solution together.

 

Best regards
Karsten Thuen

Votes for this answer: 2
 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Thanks! For now that DOMContentLoaded is enough for my needs, will let you know if there are more specific cases.

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

I see that it would be great to have an event on the receipt page of the cart which have all order details available.
We need to fire an GTM event every time a order is fulfilled.

Tried to use the Rapido.cartLoaded() event, but it is not fired in the receipt page.

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

... one more thing.
The RapidoHook.addToCart has too few details, and i cant find out where to add more to them. Can you point me in the right direction?

The details contain only these parameters.

  • productId
  • quantity
  • unitId
  • variantId

Would like to add price, and currency as well.

 
Nicolai Pedersen
Reply

It is raised in cart.js

see dump.

We will add more info to the default event.

BR Nicolai

Capture.PNG
 
Nicolai Pedersen
Reply

Hm, cannot do that on addToCart - it does not have price information.

But have a look at cartUpdated event. It has a data property which is the entire cart after update in json.

BR Nicolai

Btw: gtm is part of the next Rapido release. I would appreciate to know what tracking points you add and what data you track.

Thanks, Nicolai

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Thanks Nicolai!
Will have a look at cartUpdated, might be a good match.

Right now we are tracking all the information FB need, you can see it on this page.
https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/product-audiences#setuppixel

  • Search
  • ViewCategory
  • ViewContent
  • AddToCart
  • Purchase

Will let you know if there are others.

 

You must be logged in to post in the forum