Create SiteLink at Ad Group Level

97 views
Skip to first unread message

Peter Baptist

unread,
Feb 14, 2024, 4:00:52 AM2/14/24
to Google Ads API and AdWords API Forum
I only found samples for creating SiteLink at Campaign Level

How can I create SiteLink at Ad Group Level using Java?

Peter Baptist

unread,
Feb 14, 2024, 8:28:34 AM2/14/24
to Google Ads API and AdWords API Forum

Google Ads API Forum Advisor

unread,
Feb 14, 2024, 10:50:22 AM2/14/24
to peter.ba...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for contacting the Google Ads API support team.

I will check with our team regarding your issue and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rz63n:ref"

Thanks,
 
Google Logo Google Ads API Team


Peter Baptist

unread,
Feb 14, 2024, 1:12:47 PM2/14/24
to Google Ads API and AdWords API Forum
Thanks for your attention, but I have solved this with this code:

private void linkSitelinksToAdGroup(GoogleAdsClient googleAdsClient, List<String> sitelinkAssetResourceNames, AddSitelinkUsingAssetsParams params) {
        // Creates AdGroupAssets representing the association between sitelinks and ad groups.
        List<AdGroupAssetOperation> adGroupAssetOperations = sitelinkAssetResourceNames.stream().map(resName -> AdGroupAsset.newBuilder()
                        .setAsset(resName)
                        .setAdGroup(ResourceNames.adGroup(params.customerId, params.adGroupId))
                        .setFieldType(AssetFieldType.SITELINK)
                        .build())
                // Creates an AdGroupAssetOperation to create the AdGroupAsset.
                .map(a -> AdGroupAssetOperation.newBuilder().setCreate(a).build())
                .collect(Collectors.toList());
        // Creates the service client.
        try (AdGroupAssetServiceClient client = googleAdsClient.getLatestVersion().createAdGroupAssetServiceClient()) {
            // Sends the mutate request.
            MutateAdGroupAssetsResponse response = client.mutateAdGroupAssets(String.valueOf(params.customerId), adGroupAssetOperations);
            // Prints some information about the result.
            for (MutateAdGroupAssetResult result : response.getResultsList()) {
                System.out.printf("Linked sitelink to ad group with resource name '%s'.%n", result.getResourceName());
            }
        }
    }

Reply all
Reply to author
Forward
0 new messages