Hi Josh,

Thanks for reply,

This is the code works for me , let me know am i doing anything wrong?

Working Code:

function AddExperimentExample(AdWordsUser $user, $campaignId, $adGroupId) {
    // Get the services, which loads the required classes.
    $experimentService = $user->GetService('ExperimentService', 
ADWORDS_VERSION);
    $adGroupService = $user->GetService('AdGroupService', ADWORDS_VERSION);
    $adGroupCriterionService =
        $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);

    // Create experiment.
    $experiment = new Experiment();
    $experiment->campaignId = $campaignId;
    $experiment->name = 'ca_experiment';
    $experiment->queryPercentage = 10;

    // Set additional settings (optional).
    $experiment->startDateTime = date('Ymd His', strtotime('+1 day'));
    $experiment->endDateTime = date('Ymd His', strtotime('+1 month'));

    // Create operation.
    $experimentOperation = new ExperimentOperation();
    $experimentOperation->operand = $experiment;
    $experimentOperation->operator = 'ADD';

    $experimentOperations = array($experimentOperation);

    // Make the mutate request.
    $result = $experimentService->mutate($experimentOperations);

    // Display result.
    $experiment = $result->value[0];
    printf ("Experiment with name '%s' and ID '%.0f' was added.\n",
        $experiment->name, $experiment->id);

    // Create ad group bid multipliers to be used in the experiment.
    $adGroupBidMultipliers = new ManualCPCAdGroupExperimentBidMultipliers();
    $adGroupBidMultipliers->maxCpcMultiplier = new BidMultiplier(2);

    // Create ad group experiment data.
    $adGroupExperimentData = new AdGroupExperimentData();
    $adGroupExperimentData->experimentId = $experiment->id;
    $adGroupExperimentData->experimentDeltaStatus = 'MODIFIED';
    $adGroupExperimentData->experimentBidMultipliers = 
$adGroupBidMultipliers;



    // Create updated ad group.
    $adGroup = new AdGroup();
    $adGroup->id = $adGroupId;
    $adGroup->experimentData = $adGroupExperimentData;

    // Create operation.
    $adGroupOperation = new AdGroupOperation();
    $adGroupOperation->operand = $adGroup;
    $adGroupOperation->operator = 'SET';

    $adGroupOperations = array($adGroupOperation);

    // Make the mutate request.
    $result = $adGroupService->mutate($adGroupOperations);

    // Display result.
    $adGroup = $result->value[0];
    printf ("Ad group with name '%s' and ID '%.0f' was updated in the "
        . "experiment.\n", $adGroup->name, $adGroup->id);


    // Create ad group bid multipliers to be used in the experiment.
    $adGroupBidMultipliers = new 
ManualCPCAdGroupCriterionExperimentBidMultiplier();
    $adGroupBidMultipliers->maxCpcMultiplier = new BidMultiplier(4);

    // Create experiment data for a new experiment-only keyword.
    $adGroupCriterionExperimentData =
        new BiddableAdGroupCriterionExperimentData();
    $adGroupCriterionExperimentData->experimentId = $experiment->id;
    $adGroupCriterionExperimentData->experimentDeltaStatus = 'MODIFIED';
    
$adGroupCriterionExperimentData->experimentBidMultiplier=$adGroupBidMultipliers;

    // Create keyword.
    $keyword = new Keyword('cloud', 'BROAD');

    // Create ad group criterion.
    $adGroupCriterion = new BiddableAdGroupCriterion();
    $adGroupCriterion->adGroupId = $adGroupId;
    $adGroupCriterion->criterion = $keyword;
    $adGroupCriterion->experimentData = $adGroupCriterionExperimentData;


    // Create operation.
    $adGroupCriterionOperation = new AdGroupCriterionOperation();
    $adGroupCriterionOperation->operand = $adGroupCriterion;
    $adGroupCriterionOperation->operator = 'ADD';

    $adGroupCriterionOperations = array($adGroupCriterionOperation);

    // Make the mutate request.
    $result = $adGroupCriterionService->mutate($adGroupCriterionOperations);

    // Display result.
    $adGroupCriterion = $result->value[0];
    printf("Keyword with text '%s', match type '%s', and ID '%s' was added 
to "
        . "the experiment.\n",
        $adGroupCriterion->criterion->text,
        $adGroupCriterion->criterion->matchType,
        $adGroupCriterion->criterion->id);
}


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/994d3612-e231-4533-8446-49a37e41bc89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to