Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:51:23+00:00 2026-05-22T22:51:23+00:00

I cannot seem to parse out the metrics for an organic keyword. I am

  • 0

I cannot seem to parse out the metrics for an organic keyword. I am using simplexml_load_string to load the whole response string and then when I print_r the object I can see this:

[0] => SimpleXMLElement Object
                (
                    [id] => http://www.google.com/analytics/feeds/data?ids=ga:480&ga:keyword=cats&start-date=2011-04-10&end-date=2011-07-24
                    [updated] => 2011-07-23T17:00:00.001-07:00
                    [title] => ga:keyword=cats
                    [link] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [rel] => alternate
                                    [type] => text/html
                                    [href] => http://www.google.com/analytics
                                )

                        )

                )

But when I look at the actual (pre-formatted) response I see some extra data that didn’t survive the format:

<entry gd:etag="W/&quot;hdSFEs.&quot;" gd:kind="analytics#datarow"> 
<id>http://www.google.com/analytics/feeds/data?ids=ga:430&amp;ga:keyword=cats&amp;start-date=2011-04-10&amp;end-date=2011-07-24</id> 
<updated>2011-07-23T17:00:00.001-07:00</updated> 
<title>ga:keyword=cats</title> 
<link rel="alternate" type="text/html" href="http://www.google.com/analytics"/> 
<dxp:dimension name="ga:keyword" value="cats"/> 
<dxp:metric confidenceInterval="0.0" name="ga:organicSearches" type="integer" value="2"/> 
</entry> 

I need that metric value at the bottom, in this case it’s two. How can I get it?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:51:24+00:00Added an answer on May 22, 2026 at 10:51 pm

    Edit: the easy way out is this:

    var_dump($object->xpath('dxp:metric'));

    The problem is that simplexml has a ‘gotcha’ with namespaces. As kudo’s to squirrel, you indeed need to use namespaces, but I have a hunch that you only posted a part of the xml response and not the whole response.

    There is an excellent post about it here: http://blogs.sitepoint.com/simplexml-and-namespaces/

    In order to fetch the value of the metric (and the metric itself), you can get started with this piece of code.

    var_dump($object->children('http://schemas.google.com/analytics/2009'));
    

    Be aware that there are some attributes in there that are again in a different namespace.

    The rest also has been answered here: Parse XML with Namespace using SimpleXML

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse this json and cannot seem to figure it out. { description
I cannot seem to access the context object using a loop context is set:
I cannot seem to figure out I am getting the following error in IE
I cannot seem to find any standard algorithms that would demonstrate the requirement for
I cannot seem to debug my JavaScript code with Firebug. The play button is
i cannot seem to find the answer to this. i uploaded code to pastebin
I cannot seem to write to a file. I create the file and directory
I cannot seem to find a way to have LINQ return the value from
I cannot seem to get this date picker working at all. I know it
I cannot seem to get the quotes around this statement right. No matter what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.