Analytics
5.3K members online now
5.3K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Ecommerce Code Please Check

Participant ✭ ☆ ☆
# 1
Participant ✭ ☆ ☆

I've asked a web dev to add the needed code to a site for ecomm tracking. He sent me this:

 

<script>
	ga('require', 'ecommerce');
	
	ga('ecommerce:addTransaction', {
	  'id': '{transaction_id}',                     // Transaction ID. Required.
	  'affiliation': 'Rudells',   // Affiliation or store name.
	  'revenue': '{order_total}',               // Grand Total.
	  'shipping': '{order_shipping}',                  // Shipping.
	  'tax': '{order_tax}'                     // Tax.{order_total}
	});
	
	{exp:cartthrob:order_items order_id="{entry_id}" }
	ga('ecommerce:addItem', {
	  'id': '{transaction_id}',                     // Transaction ID. Required.
	  'name': '{item:title}',    // Product name. Required.
	  'sku': '{rudell_code}',                 // SKU/code.
	  'category': '{item:category1} > {item:category2} > {item:category3}',         // Category or variation.
	  'price': '{item:price}',                 // Unit price.
	  'quantity': '{item:quantity}'                   // Quantity.
	});
	{/exp:cartthrob:order_items}
	
	ga('ecommerce:send');
</script>

I know he has left the comments in there (which I don't think should cause issues) but can someone please check it over to make sure there are no more errors. Thanks!

Ecommerce Code Please Check

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

That doesn't look like valid JS.

 

It looks like valid JS combined with Smarty template tags like Shopify uses.

 

That aside, JS Hint and JS Lint are 2 of the best known tools for checking the validity of JS syntax, googling either will give you online tools to paste you code into and get an answer if it's valid JS.

 

Due to the template tags, you're probably just going to need to wait and see...implement, test, and see if the reports match the test.