Need to add some tracking script to a button, how? HELP!

Hello there!

I need to add this analytics script to a button, can someone guide me on how to do it, please?

    if (typeof window.analytics !== 'undefined') {
    window.analytics.track('Started Form', {
      action: 'track',
      event: 'Started Form',
      properties: {
        category: 'Lead-1',
        label: 'Started Form',
        value: 1
      },
      from: 'Homepage'
    })
  }

thanks!