Skip to content

E-Commerce Tracking via Google Analytic 4 #37

Answered by vettloffah
dannyleungkc asked this question in Help
Discussion options

You must be logged in to vote

Here's a helper function to post dataLayer events from swell data that I use in our site front end. This requires that you have the GTM script loaded in every page.

/**
 * Add an ecommerce event to the datalayer for google tag manager
 * @param name - event name, e.g. 'add_to_cart'
 * @param items - array of swell products or swell cart items that are included in the event
 * @param value - dollar value of the event
 * @param cart - pass in cart data if we want the current cart contents updated on the dataLayer
 * (separate from the `ecommerce` event data)
 */
export default function gtmEcommEvent( name, items, value, cart) {
	// add cart contents to dataLayer if cart object was passed in…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@osseonews
Comment options

@dannyleungkc
Comment options

@vettloffah
Comment options

Comment options

You must be logged in to vote
1 reply
@logeshswell
Comment options

Answer selected by logeshswell
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment