Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9005 manish.sha 1
// Copyright 2012 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
package adwords.axis.v201309.remarketing;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201309.cm.AdWordsConversionTracker;
19
import com.google.api.ads.adwords.axis.v201309.cm.AdWordsConversionTrackerMarkupLanguage;
20
import com.google.api.ads.adwords.axis.v201309.cm.AdWordsConversionTrackerTextFormat;
21
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTracker;
22
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTrackerCategory;
23
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTrackerOperation;
24
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTrackerReturnValue;
25
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTrackerServiceInterface;
26
import com.google.api.ads.adwords.axis.v201309.cm.ConversionTrackerStatus;
27
import com.google.api.ads.adwords.axis.v201309.cm.Operator;
28
import com.google.api.ads.adwords.lib.client.AdWordsSession;
29
import com.google.api.ads.common.lib.auth.OfflineCredentials;
30
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
31
import com.google.api.client.auth.oauth2.Credential;
32
 
33
/**
34
 * This example adds an AdWords conversion.
35
 *
36
 * Credentials and properties in {@code fromFile()} are pulled from the
37
 * "ads.properties" file. See README for more info.
38
 *
39
 * Tags: ConversionTrackerService.mutate
40
 *
41
 * @author Kevin Winter
42
 */
43
public class AddConversionTracker {
44
 
45
  public static void main(String[] args) throws Exception {
46
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
47
    // and can be used in place of a service account.
48
    Credential oAuth2Credential = new OfflineCredentials.Builder()
49
        .forApi(Api.ADWORDS)
50
        .fromFile()
51
        .build()
52
        .generateCredential();
53
 
54
    // Construct an AdWordsSession.
55
    AdWordsSession session = new AdWordsSession.Builder()
56
        .fromFile()
57
        .withOAuth2Credential(oAuth2Credential)
58
        .build();
59
 
60
    AdWordsServices adWordsServices = new AdWordsServices();
61
 
62
    runExample(adWordsServices, session);
63
  }
64
 
65
  public static void runExample(
66
      AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
67
    // Get the ConversionTrackerService.
68
    ConversionTrackerServiceInterface service =
69
        adWordsServices.get(session, ConversionTrackerServiceInterface.class);
70
 
71
    // Create AdWords conversion.
72
    AdWordsConversionTracker adWordsConversionTracker = new AdWordsConversionTracker();
73
    adWordsConversionTracker.setName("Earth to Mars Cruises Conversion # "
74
        + System.currentTimeMillis());
75
    adWordsConversionTracker.setCategory(ConversionTrackerCategory.DEFAULT);
76
    adWordsConversionTracker.setMarkupLanguage(AdWordsConversionTrackerMarkupLanguage.HTML);
77
    adWordsConversionTracker.setTextFormat(AdWordsConversionTrackerTextFormat.HIDDEN);
78
 
79
    // You can optionally provide these field(s).
80
    adWordsConversionTracker.setStatus(ConversionTrackerStatus.ENABLED);
81
    adWordsConversionTracker.setViewthroughLookbackWindow(15);
82
    adWordsConversionTracker.setIsProductAdsChargeable(Boolean.TRUE);
83
    adWordsConversionTracker.setProductAdsChargeableConversionWindow(15);
84
    adWordsConversionTracker.setConversionPageLanguage("en");
85
    adWordsConversionTracker.setBackgroundColor("#0000FF");
86
    adWordsConversionTracker.setUserRevenueValue("someJavascriptVariable");
87
 
88
    // Create operations.
89
    ConversionTrackerOperation operation = new ConversionTrackerOperation();
90
    operation.setOperator(Operator.ADD);
91
    operation.setOperand(adWordsConversionTracker);
92
 
93
    ConversionTrackerOperation[] operations = new ConversionTrackerOperation[] {operation};
94
 
95
    // Add conversion.
96
    ConversionTrackerReturnValue result = service.mutate(operations);
97
 
98
    // Display conversion.
99
    for (ConversionTracker conversionTracker : result.getValue()) {
100
      if (conversionTracker instanceof AdWordsConversionTracker) {
101
        AdWordsConversionTracker newAdWordsConversionTracker =
102
            (AdWordsConversionTracker) conversionTracker;
103
        System.out.printf("Conversion with id \"%d\", name \"%s\", status \"%s\", "
104
            + "category \"%s\" and snippet \"%s\" was added.\n",
105
            newAdWordsConversionTracker.getId(), newAdWordsConversionTracker.getName(),
106
            newAdWordsConversionTracker.getStatus(), newAdWordsConversionTracker.getCategory(),
107
            newAdWordsConversionTracker.getSnippet());
108
      } else {
109
        System.out.printf("Conversion with id \"%d\", name \"%s\", status \"%s\", "
110
            + "category \"%s\" was added.\n", conversionTracker.getId(),
111
            conversionTracker.getName(), conversionTracker.getStatus(),
112
            conversionTracker.getCategory());
113
      }
114
    }
115
  }
116
}