Google Ads Links: insert

נדרשת הרשאה

יוצר קישור בין נכס אינטרנט ל-Google Ads. אפשר לנסות עכשיו או לראות דוגמה.

בקשה

בקשת HTTP

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/entityAdWordsLinks

פרמטרים

שם הפרמטר ערך תיאור
פרמטרים של נתיב
accountId string מזהה חשבון Google Analytics שעבורו רוצים ליצור את הקישור.
webPropertyId string מזהה נכס אינטרנט שעבורו רוצים ליצור את הקישור.

אישור

הבקשה הזו מחייבת הרשאה עם ההיקף הבא (מידע נוסף על אימות והרשאה).

היקף
https://www.googleapis.com/auth/analytics.edit

גוף הבקשה

בגוף הבקשה, מציינים משאב מסוג Google Ads Links (קישורים ל-Google Ads) עם המאפיינים הבאים:

שם הנכס ערך תיאור הערות
המאפיינים הנדרשים
adWordsAccounts[] list רשימה של חשבונות לקוח ב-Google Ads. הם לא יכולים להיות חשבונות ניהול (MCC). חובה למלא את השדה הזה כשיוצרים קישור ל-Google Ads. אי אפשר להשאיר את השדה ריק. ניתן לכתיבה
adWordsAccounts[].customerId string מספר לקוח. חובה למלא את השדה הזה כשיוצרים קישור ל-Google Ads.
name string שם הקישור. חובה למלא את השדה הזה כשיוצרים קישור ל-Google Ads. ניתן לכתיבה

תשובה

אם הפעולה בוצעה בהצלחה, השיטה הזו מחזירה משאב של קישורים ל-Google Ads בגוף התשובה.

דוגמאות

הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).

Java

משתמש בספריית הלקוח של Java.

/*
 * Note: this code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */

// Construct a list of AdWordsAccounts.
AdWordsAccount adWordsAccount = new AdWordsAccount();
adWordsAccount.setCustomerId("123-456-7890");
List<AdWordsAccount> adWordsAccounts = Arrays.asList(adWordsAccount);

// Construct the body of the request.
EntityAdWordsLink adWordsLink = new EntityAdWordsLink();
adWordsLink.setAdWordsAccounts(adWordsAccounts);
adWordsLink.setName("Google Ads Link");

try{
  analytics.management().webPropertyAdWordsLinks().insert("123456",
      "UA-123456-1", adWordsLink).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

PHP

משתמש בספריית הלקוח של PHP.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/**
 * This request creates a new Google Ads Link.
 */

// Construct an Google Ads account object.
$adWordsAccount = new Google_Service_Analytics_AdWordsAccount();
$adWordsAccount->setCustomerId("123-456-7890");

// Construct the body of the request.
$adWordsLink = new Google_Service_Analytics_EntityAdWordsLink();
$adWordsLink->setName('Google Ads Link');
$adWordsLink->setAdWordsAccounts(array($adWordsAccount));

try {
  $analytics->management_webPropertyAdWordsLinks->insert('123456',
      'UA-123456-1', $adWordsLink);

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

Python

משתמש בספריית הלקוח של Python.

# Note: This code assumes you have an authorized Analytics service object.
# See the Google Ads Links Developer Guide for details.

# This request creates a new Google Ads Link.
try:
  analytics.management().webPropertyAdWordsLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      body={
          'adWordsAccounts': [
              {
                  'customerId': '123-456-7890'
              }
          ],
          'name': 'Google Ads Link'
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

JavaScript

נעשה שימוש בספריית הלקוח של JavaScript.

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */
function insertAdWordsLink() {
  var request = gapi.client.analytics.management.webPropertyAdWordsLinks.insert(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'resource': {
        'adWordsAccounts': [ { 'customerId': '123-456-7890'} ],
        'name': 'Google Ads Link'
      }
    });
  request.execute(function (response) { // Handle the response. });
}

רוצה לנסות?

צריך להשתמש ב-APIs Explorer שבהמשך כדי לקרוא לשיטה הזו בנתונים בזמן אמת ולראות את התגובה. לחלופין, אפשר לנסות את ה-Explorer העצמאי.