Get Started

Adding the Google Domains widget to your site is a straightforward process. Just follow these steps:

1. Set up your account

Contact Google Domains to apply to be a partner. Once approved, we will set up a new account that you will need to configure. When you configure your account, you will be setting a template which will determine the behavior of domains registered through your widget. This template will include:

  • The resource records that you would like automatically added to new domains. For instance, you can set A, AAAA, CNAME, and MX, etc., records to have your web service automatically configured by default
  • The domain you want to use the widget on. You may also choose to include subdomains.
  • Any relevant fields you want to pass to Google Domains

Keep in mind that you can set up as many templates as you want, or have no template or preset resource records at all. We’ll also give you access to all the images and other assets you’ll need to complete the integration.

2. Import the API source

Add the following script source to the head element of your website document

<script src=”https://apis.google.com/js/api.js”></script>

3. Invoke the widget API

Add the following Javascript skeleton to the head element of your website document:

    <script type="javascript">
    gapi.load(‘domains’, function() {
        gapi.domains.searchAndBuy(
        {
            partnerId: /*RQ*/,
            successUrl: /*RQ*/,
            cancelUrl: /*RQ*/,
            defaultQuery: /*Opt*/,
            defaultTlds: /*Opt*/,
            template: { /*RQ if using multiple templates*/
                templateId: /*RQ*/,
                vars: {
                    /*Opt*/
                },
            },
            hints: { /*Opt*/
                additionalServices: ["email"], /*Opt*/
            }
        });
    });
    </script>

Then, populate the fields as follows:

Parameters
partnerId string, required
Your partner code. This should should have been given to you when you contacted Google Domains in step 1.
successUrl string, required
The URL that you would like users to be returned to once they purchased their domain. This URL may contain any fields you pass into the function. This URL may append the name of the domain that was purchased, which will be a reserved variable provided by Google Domains as %domain%. Please note: this URL must use https protocol. Sample URL: "www.example.com/success?uid="+userId+"&domain=%domain%"
cancelURL string, required
The URL that you would like users to be returned to if there were any errors or cancellations during the purchase process. Users that fail to purchase a domain for any reason will be redirected to this URL. This field follows the same format as the successURL field. Please note: this URL must use https protocol.
defaultQuery string, optional
This field contains the default search query when the widget loads.
defaultTlds string array, optional
This is an array of top-level domains that will be set as the default filter options in search results. Example: ["com", "cc", "florist", "ninja"]
template field, conditionally required
This optional field contains information on which template you want to associate with the user. This field can be omitted if you do not have a template.
templateId string, cond. required
The name of the template you want to use for this page. This should have been created during the setup of your template in step 1. This field is required if you decide to use a template.
vars string, cond. required
Any fields you wish to use in the template. These should be passed in key:value format, such as “blog_id” : “3”. These fields should have been specified during the setup process in step 1. Note that the widget will self-destruct if the parameters passed in are different from those specified during setup. The variable %domain% is reserved and is automatically populated with the domain name purchased by the user, so you can use it in your resource records if necessary.
hints/additionalServices field, optional
This optional field contains other services you may want to offer to your customers. Currently, you may include G Suite, which offers custom email along with other services, into the registration flow by specifying '["email"]' under additionalServices.

4. Create a wrapper function

    function showGoogleDomainsFlow() { /*Defined function*/
        gapi.load(‘domains’, function() {
            gapi.domains.searchAndBuy({
                ....
            });
        });
    }

5. Invoke the function

    <button onclick=”showGoogleDomainsFlow()”>Buy a domain </button>

The end result should look like the following:

    <head>
        ....
        <script src=”https://apis.google.com/js/api.js”></script>
        <script type="javscript">
        function showGoogleDomainsFlow() {
            gapi.load(‘domains’, function() {
                gapi.domains.searchAndBuy({
                    ....
                });
            });
        }
        </script>
        ....
    </head>

    <body>
        ....
        <button onclick=”showGoogleDomainsFlow()”>Buy a domain</button>
        ....
    </body>