Recognize JS cookie in shipping script

Nikolas_Alexand
New Member
28 0 0

I am using Monetate (AB platform) to test free shipping on orders over $75 (50/50 traffic split). If a session is in the experiment group, Monetate creates a JS cookie. Is it possible for a Shopify shipping script to recgonize the presence of that JS cookie value?

If so, i want to append that code to this existing prefab script for free UPS ground shipping on orders over $75 - 

 

MINIMUM_ORDER_AMOUNT = 75 #dollars required in cart to get discount
DISCOUNT = 1.0 #percentage discount (in decimal format)

if Input.cart.subtotal_price_was > (Money.new(cents:100) * MINIMUM_ORDER_AMOUNT)
  Input.shipping_rates.each do |shipping_rate|
    next unless shipping_rate.source == "shopify"
    next unless shipping_rate.name == "UPS Ground"
    shipping_rate.apply_discount(shipping_rate.price * DISCOUNT, message: MESSAGE)
  end
end

Output.shipping_rates = Input.shipping_rates

 

(I also spliced this one together, one of these should work though, haha.)

MINIMUM_ORDER_AMOUNT = 75 #dollars required in cart to get discount

if Input.cart.subtotal_price_was > (Money.new(cents:100) * MINIMUM_ORDER_AMOUNT)
Input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  next unless shipping_rate.name == "UPS Ground"
  shipping_rate.apply_discount(shipping_rate.price)
end

Output.shipping_rates = Input.shipping_rates

 

Thanks!!

0 Likes
Jason
Shopify Expert
10041 119 1877

Shopify Scripts run on the server before the content is sent to the viewer - so they can't read browser side cookies.

You'll need to approach the A/B testing in a different way. Perhaps by having the A/B script add a custom item to the cart, or a line item property so that Scripts can detect it, passing a 0% discount code, etc.

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Nikolas_Alexand
New Member
28 0 0

I don't think Monetate has the ability to modify the shopping cart. 

 

Any other ideas?

0 Likes
Nikolas_Alexand
New Member
28 0 0

Bump

0 Likes
Jason
Shopify Expert
10041 119 1877

Here's a couple of options:

  • use the carrierservice API and have the app return rates with or without free shipping
  • add line item properties to the items in the cart (before checkout) and have those determine if free shipping is shown or not. there's some risk here that clever people will see/exploit that.

I don't know what info you can pull from Monetate to determine if a line item property should be added or not. I'd assume there would be a way to leverage their data to get a simple boolean response.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Nikolas_Alexand
New Member
28 0 0

Thanks Jason.

Can the carrierservice API return rates based on the presence of a cookie? If that were the case, I could have Monetate set a JS cookie for the experiment. You can also modify JS variables and html elements with Monetate for experiment sessions.

 

Adding a line item to cart is probably not a solution, unfortunately, because we have some custom cart code that won't allow for it. 

0 Likes