public function __invoke()
 {
     $today = $this->getDateInThePast(0);
     $oneWeekAgo = $this->getDateInThePast(7);
     $twoWeeksAgo = $this->getDateInThePast(14);
     $threeWeeksAgo = $this->getDateInThePast(21);
     $service = $this->adwords->getService('AdGroupService');
     $selector = new \Selector();
     $selector->predicates = [new \Predicate('Status', 'EQUALS', 'ENABLED'), new \Predicate('CampaignStatus', 'EQUALS', 'ENABLED')];
     $selector->orderBy = new \OrderBy('ctr', 'ASCENDING');
     $selector->paging = new \Paging(0, \AdWordsConstants::RECOMMENDED_PAGE_SIZE);
     do {
         $page = $service->get($selector);
         if (is_array($page->entries)) {
             foreach ($page->entries as $adGroup) {
                 // Let's look at the trend of the ad group's CTR.
                 $statsThreeWeeksAgo = $this->getStatsFor($adGroup, $threeWeeksAgo, $twoWeeksAgo);
                 $statsTwoWeeksAgo = $this->getStatsFor($adGroup, $twoWeeksAgo, $oneWeekAgo);
                 $statsLastWeek = $this->getStatsFor($adGroup, $oneWeekAgo, $today);
                 // Week over week, the ad group is declining - record that!
                 if ($statsLastWeek->getCtr() < $statsTwoWeeksAgo->getCtr() && $statsTwoWeeksAgo->getCtr() < $statsThreeWeeksAgo->getCtr()) {
                     reportRows . push([adGroup . getCampaign() . getName(), adGroup . getName(), statsLastWeek . getCtr() * 100, statsLastWeek . getCost(), statsTwoWeeksAgo . getCtr() * 100, statsTwoWeeksAgo . getCost(), statsThreeWeeksAgo . getCtr() * 100, statsThreeWeeksAgo . getCost()]);
                 }
             }
         }
         $selector->paging->startIndex += $selector->paging->numberResults;
     } while (!is_null($page->entries));
 }
示例#2
0
                                        <p><label>19-40 age:</label> 25%</p>
                                        <p><label>40+ age:</label> 5%</p>
                                    </div>
                                </div>
                                
                            </div><!-- ad-item -->
                            <?php 
            }
            ?>

                <?php 
        }
    }
}
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
    $campaign = getCampaign(intval($_GET['cid']));
    $id = $campaign['project_id'];
    $countries = getCountries();
    ?>
                    <div class="content-title">Select your thematic post:</div>

                    <form action="" method="post">
                        <div class="form-item no-height thematic">
                            <?php 
    $video = getFeaturingVideo($id);
    if (!empty($video)) {
        for ($i = 1; $i < 5; $i++) {
            ?>
                                    <div class="thematic_item">
                                        <label for="thematic_post_<?php 
            echo $i;
 public function __invoke()
 {
     $this->createLabel();
     $alert_text = [];
     $history = [];
     $currentTime = new \DateTime();
     $today = $currentTime->format('m') + 1 + "/" + $currentTime . getDate() + "/" + $currentTime->format('Y');
     $keywordIterator;
     $line_counter = 0;
     while ($keywordIterator->hasNext()) {
         $keyword = keywordIterator . next();
         $line_counter++;
         $current_quality_score = $keyword->qualityScore;
         $keywordLabelsIterator = keyword . labels() . withCondition("Name STARTS_WITH 'QS: '") . get();
         if ($keywordLabelsIterator->hasNext()) {
             $keyword_label = $keywordLabelsIterator . next();
             $matches = new RegExp('QS: ([0-9]+)$') . exec($keyword_label . getName());
             $old_quality_score = $matches[1];
         } else {
             $old_quality_score = 0;
         }
         // For the history also note the change or whether this keyword is new
         if ($old_quality_score > 0) {
             $change = $current_quality_score - $old_quality_score;
         } else {
             $change = "NEW";
         }
         $row = [$today, $keyword . getCampaign() . getName(), $keyword . getAdGroup() . getName(), $keyword . getText(), $current_quality_score, $change];
         $history . push(row);
         // If there is a previously tracked quality score and it's different from the current one...
         if ($old_quality_score > 0 && $current_quality_score != $old_quality_score) {
             // Make a note of this to log it and possibly send it via email later
             $alert_text . push($current_quality_score + "\t" + $old_quality_score + "\t" + $change + "\t" + $keyword . getText());
             // Remove the old label
             $keyword . removeLabel($keyword_label . getName());
         }
         // Store the current QS for the next time by using a label
         $keyword . applyLabel("QS: " + $current_quality_score);
     }
     if ($line_counter == 0) {
         $this->logger->log("Couldn't find any keywords marked for quality score tracking. To mark keywords for tracking, apply the label '" + $label_name + "' to those keywords.");
         return;
     }
     $this->logger->log("Tracked " + $line_counter + " keyword quality scores. To select different keywords for tracking, apply the label '" + $label_name + "' to those keywords.");
     // Store history
     $history_sheet = spreadsheet . getSheetByName('QS history');
     $history_sheet . getRange($history_sheet . getLastRow() + 1, 1, $history . length, 6) . setValues($history);
     // If there are notes for alerts then prepare a message to log and possibly send via email
     if ($alert_text . length) {
         $message = "The following quality score changes were discovered:\nNew\tOld\tChange\tKeyword\n";
         for ($i = 0; $i < count($alert_text); $i++) {
             $message += $alert_text[i] + "\n";
         }
         // Also include a link to the spreadsheet
         $message += "\n" + "The complete history is available at " + $spreadsheet . getUrl();
         $this->logger->log($message);
         // If there is an email address send out a notification
         if ($email_address && $email_address != "YOUR_EMAIL_HERE") {
             $this->mailer->sendEmail($email_address, "Quality Score Tracker: Changes detected", $message);
         }
     }
 }