/** * Search for current site in account list, in order * to find its Google id. If not found, defaults to * first site in list * * @param array of object $accounts */ public static function getDefaultAccountId($accounts) { $id = 0; if (!empty($accounts)) { // search for current site $current = Sh404sefHelperAnalytics::getWebsiteName(); foreach ($accounts as $account) { if (strpos($current, $account->title) !== false or strpos(str_replace('www.', '', $current), $account->title) !== false) { $id = $account->id; break; } } // default to first account if no match found $id = empty($id) ? $accounts[0]->id : $id; } return $id; }