Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

const (
baseUrl = "https://adwords.google.com/api/adwords/cm/v201409"
baseUrl = "https://adwords.google.com/api/adwords/cm/v201809"
mcmUrl = "https://adwords.google.com/api/adwords/mcm/v201809"
)

type ServiceUrl struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ var (
geoLocationServiceUrl = ServiceUrl{baseUrl, "GeoLocationService"}
labelServiceUrl = ServiceUrl{baseUrl, "LabelService"}
locationCriterionServiceUrl = ServiceUrl{baseUrl, "LocationCriterionService"}
managedCustomerServiceUrl = ServiceUrl{baseUrl, "ManagedCustomerService"}
managedCustomerServiceUrl = ServiceUrl{mcmUrl, "ManagedCustomerService"}
mediaServiceUrl = ServiceUrl{baseUrl, "MediaService"}
mutateJobServiceUrl = ServiceUrl{baseUrl, "Mutate_JOB_Service"}
offlineConversionFeedServiceUrl = ServiceUrl{baseUrl, "OfflineConversionFeedService"}
Expand Down
2 changes: 1 addition & 1 deletion base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func rand_word(str_size int) string {
return string(bytes)
}

func testAuthSetup(t *testing.T) Auth {
func testAuthSetup(t *testing.T) *Auth {
config, err := NewCredentials(context.TODO())
if err != nil {
t.Fatal(err)
Expand Down
45 changes: 45 additions & 0 deletions conversion_tracker.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
package gads

import (
"encoding/xml"
)

type ConversionTrackerService struct {
Auth
}

func NewConversionTrackerService(auth *Auth) *ConversionTrackerService {
return &ConversionTrackerService{Auth: *auth}
}

type ConversionTracker struct {
Id int64 `xml:"id"`
OriginalConversionTypeId int64 `xml:"originalConversionTypeId"`
Name string `xml:"name"`
Status string `xml:"status"`
Category string `xml:"category"`
GoogleEventSnippet string `xml:"googleEventSnippet"`
GoogleGlobalSiteTag string `xml:"googleGlobalSiteTag"`
}

func (c *ConversionTrackerService) Get(selector Selector) (conversions []ConversionTracker, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := c.Auth.request(
conversionTrackerServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return conversions, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Conversions []ConversionTracker `xml:"rval>entries"`
}{}

err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return conversions, totalCount, err
}
return getResp.Conversions, getResp.Size, err
}
50 changes: 50 additions & 0 deletions managed_customer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
package gads

import (
"encoding/xml"
)

type ManagedCustomerService struct {
Auth
}

func NewManagedCustomerService(auth *Auth) *ManagedCustomerService {
return &ManagedCustomerService{Auth: *auth}
}

type AccountLabel struct {
Id string `xml:"id"`
Name string `xml:"name"`
}

type Account struct {
Name string `xml:"name,omitempty"`
CanManageClients bool `xml:"canManageClients,omitempty"`
ExcludeHiddenAccounts bool `xml:"excludeHiddenAccounts,omitempty"`
CustomerId string `xml:"customerId,omitempty"`
DateTimeZone string `xml:"dateTimeZone,omitempty"`
CurrencyCode string `xml:"currencyCode,omitempty"`
AccountLabels []AccountLabel `xml:"accountLabels,omitempty"`
}

func (m *ManagedCustomerService) Get(selector Selector) (accounts []Account, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := m.Auth.request(
managedCustomerServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: mcmUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return accounts, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Accounts []Account `xml:"rval>entries"`
}{}

err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return accounts, totalCount, err
}
return getResp.Accounts, getResp.Size, err
}
2 changes: 1 addition & 1 deletion oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AuthConfig struct {
OAuth2Config *oauth2.Config `json:"oauth2.Config"`
OAuth2Token *oauth2.Token `json:"oauth2.Token"`
tokenSource oauth2.TokenSource `json:"-"`
Auth Auth `json:"gads.Auth"`
Auth *Auth `json:"gads.Auth"`
}

func NewCredentialsFromFile(pathToFile string, ctx context.Context) (ac AuthConfig, err error) {
Expand Down
58 changes: 58 additions & 0 deletions offline_conversion_feed.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
package gads

import "encoding/xml"

type OfflineConversionService struct {
Auth
}

const (
uploadConversionAction = "ADD"
)

type OfflineConversionFeed struct {
GoogleClickId string `xml:"googleClickId"`
ConversionName string `xml:"conversionName"`
ConversionTime string `xml:"conversionTime"`
ConversionCurrencyCode string `xml:"conversionCurrencyCode"`
ExternalAttributionModel string `xml:"externalAttributionModel"`
ConversionValue float32 `xml:"conversionValue"`
ExternalAttributionCredit float32 `xml:"externalAttributionCredit"`
}

type OfflineConversionOperations map[string][]OfflineConversionFeed

func NewOfflineConversionService(auth *Auth) *OfflineConversionService {
return &OfflineConversionService{Auth: *auth}
}

func (o *OfflineConversionService) Mutate(conversionOperations OfflineConversionOperations) (conversion []OfflineConversionFeed, error error) {
type conversionOperation struct {
Action string `xml:"operator"`
Conversion OfflineConversionFeed `xml:"operand"`
}
var ops []conversionOperation

for _, conversion := range conversionOperations {
for _, con := range conversion {
ops = append(ops,
conversionOperation{
Action: uploadConversionAction,
Conversion: con,
},
)
}
}
mutation := struct {
XMLName xml.Name
Ops []conversionOperation `xml:"operations"`
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "mutate",
},
Ops: ops}
respBody, err := o.Auth.request(offlineConversionFeedServiceUrl, "mutate", mutation)
if err != nil {
return conversion, err
}
mutateResp := struct {
Conversions []OfflineConversionFeed `xml:"rval>value"`
}{}
err = xml.Unmarshal([]byte(respBody), &mutateResp)
if err != nil {
return conversion, err
}
return mutateResp.Conversions, nil
}