The easiest way to attribute leads to Google Analytics user ids is to use Formsable app, which does it automatically.
The first step is to locate the Google Analytics tracking id for the property you’d like to use for reporting.
Open Google Analytics, Admin – Property Settings page. Tracking Id should be the first item on the list. Record it.
After completing general Formsable setup, open ‘API Credentials’ tab. Select ‘Google Analytics’ service and enter Tracking Id in the Access Token field. Leave Refresh Token blank and enter arbitrary name you’d like to use as a reference (for example, corresponding Google Analytics property name). Press ‘Save’.
Open ‘Outbound’ tab. Select the Google Analytics Credential you’ve just saved and ‘Lead’ event type. Press ‘Save’.
At this point required integration setup is complete and Formsable will start sending all Leads it attributed to Google Analytics visitors to Google Analytics Measurement API. Conversions will appear in all standard reports; additionally, Purchases will appear in the Conversions tab of E-commerce reports.
Events can be sent to Formsable from custom apps using its inbound webhook. This is convenient to attribute purchases and other conversions that aren't necessarily reflected in the payment system. For example, when the service usage accumulates before being invoiced once a payment threshold is reached or next billing cycle occurs.