Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[SD-944] Adds 'remove from cart' event for GA #53

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//= require spree/frontend

function gaRemoveFromCart(variant) {
clearGAplugins();
gtag(
'event',
'remove_from_cart',
{
items: [{
id: variant.sku,
name: variant.name,
price: variant.price,
variant: variant.options,
quantity: variant.quantity
}]
}
);
}

Spree.ready(function(){
$('body').on('product_remove_from_cart', function(event) {
var variant = {
sku: event.variant_sku,
name: event.variant_name,
price: event.variant_price,
options: event.variant_options,
quantity: event.variant_quantity
}

if (typeof gtag !== 'undefined') {
gaRemoveFromCart(variant)
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def add_javascripts
return unless File.file?(javascripts_path)

append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/add_to_cart_analytics\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/remove_from_cart_analytics\n"
end

def add_migrations
Expand Down