Search code examples
jqueryamazon-pay

GA Event Tracking on Amazon button


We cannot control the code of Amazon button because Amazon Generated it themselves.

My question it can I do it externally like this?

$j(#OffAmazonPaymentsWidgets0).click({
_gaq.push(['_trackEvent', 'Category', 'Action', 'Extra Label if you like!']);
});

Thanks!


Solution

  • The JS code within the authorization callback is executed upon click of the button. So you could do something like this:

    var authRequest;
    OffAmazonPayments.Button("AmazonPayButton", "YOUR_SELLER_ID_HERE", {
      type:  "PwA",
      color: "Gold",
      size:  "medium",
      useAmazonAddressBook: true,
      authorization: function() {
    
        // additional on click code
        _gaq.push(['_trackEvent', 'Category', 'Action', 'Extra Label if you like!']);
    
        var loginOptions = {scope: 'profile payments:widget'};
        authRequest = amazon.Login.authorize(loginOptions, "YOUR_REDIRECT_URL_HERE");
      },
      onError: function(error) {
        // Write your custom error handling
      }
    });