Hi,
Using Google Tag Manager the best way to integrate with Consent Mode is to use Consent Configuration and a Consent API in a Tag Template:
https://support.google.com/tagmanager/answer/10718549
https://developers.google.com/tag-manager/templates/consent-apis
If you are using a Consent Management Provider (CMP) that has already integration with GTM and Consent Mode, you will not need any gtag() call.
If you have your custom made CMP, it is still better to write a tag template using the Consent API provided in the Sandbox API.
If you still want to use the gtag() commmand, you will need to add another line before your gtag() command in order this to work:
function gtag(){window.dataLayer.push(arguments);}