Created
July 26, 2017 18:12
-
-
Save r0b3r70/2f9589913921307e79cbd15a0f1bb2eb to your computer and use it in GitHub Desktop.
Google Analytics for Ommwriter fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// find button once | |
var button = document.getElementById('place_order'), | |
var price = form.find('.woocommerce-Price-amount').text(); | |
// check if button even exists | |
if(button !== null) { | |
// listen for events on the button | |
button.addEventListener('click', function(event) { | |
// if you need this | |
var href = this.href; | |
// so that we can do fancy stuff before actually submitting | |
event.preventDefault(); | |
// in case fancy stuff takes too long, we do want to proceed | |
// so the user won't be prevented | |
setTimeout(followLink, 1000); | |
// we did not proceed yet so we keep a record of that state | |
var linkFollowed = false; | |
// you get the point... | |
function followLink() { | |
if (!linkFollowed) { | |
linkFollowed = true; | |
window.location = href; | |
} | |
} | |
// submit google analytics | |
ga('checkout form', 'Submit Product', 'product', price, { | |
// named function so you can see it in your console if needed | |
hitCallback: function() { | |
window.location = href; | |
} | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment