In Magento 2 I need to invoke some JS tracking when the following things happen:
- customer logs into site
- customer registers account
- newsletter subscribe success
- customer updates account details
- order success
Apart from order success which has an actual page to trigger the JavaScript, I'm not sure on the best way to track the other events seeing as their success seems to be fully handled by PHP only.
Regarding the login/register requirement I have seen that there's a JS handler in module-customer/view/frontend/web/js/action/login.js
which has this:
action.registerLoginCallback = function(callback) {
callbacks.push(callback);
};
But I'm not sure how this can be hooked into in my module. Are there any resources that could help here? I'm just looking for suggestions on the best practice way to approach this.