skardhamar / rga

R Google Analytics
187 stars 90 forks source link

How to use ga:date in advanced segments #72

Open omarcheek opened 8 years ago

omarcheek commented 8 years ago

when I'm trying to execute this code:

ga.data= ga$getData(Gaid, batch = TRUE, walk = TRUE, start_date, end_date,

                    metrics = "ga:screenViews",
                    dimensions = "ga:screenName",
                    sort = "", filters = "", segment = "users::condition::ga:userType==New%20Visitor;ga:dimension1==test_17; ga:date==2015-08-03")

I have the following error: error in fetching data: ga:date is not allowed in advanced segments.

Help me please I need to find out the number of screenviews made by new visitors, whose first session date was 2015-08-03

omarcheek commented 8 years ago

I tried to use ga:dateOfSession but it did not work

mattpolicastro commented 8 years ago

Hi @omarcheek, it doesn't look like ga:dateOfSession is a supported dimension in the API: https://developers.google.com/analytics/devguides/reporting/core/dimsmets

Instead, have you tried using ga:date==2015-08-03 as a filter, instead of a segment? Or simply specified the start_date and end_date params as `2015-08-03'?

MarkEdmondson1234 commented 8 years ago

I would recommend using this online API tool first to check which dims you should and can use: https://ga-dev-tools.appspot.com/query-explorer/ https://ga-dev-tools.appspot.com/query-explorer/

On 10 Aug 2015, at 17:36, Matt Policastro notifications@github.com wrote:

Hi @omarcheek https://github.com/omarcheek, it doesn't look like ga:dateOfSession is a supported dimension in the API: https://developers.google.com/analytics/devguides/reporting/core/dimsmets https://developers.google.com/analytics/devguides/reporting/core/dimsmets Instead, have you tried using ga:date==2015-08-03 as a filter, instead of a segment? Or simply specified the start_date and end_date params as `2015-08-03'?

— Reply to this email directly or view it on GitHub https://github.com/skardhamar/rga/issues/72#issuecomment-129498555.

omarcheek commented 8 years ago

@mattpolicastro I Tried to use ga:date as a filter but that is not what I need. This Filter will simply cut the users with a specific date during the period

what I need is to find out the number of New users whose first date of visit is 2015-08-03. That also means that they can have some sessions on 2015-08-04, 2015-08-05 and so on

@MarkEdmondson1234 I tried your solution. and still no success.

I have built in user segment as following: users who are New Visitors with the Date of session 2015-08-03 when I try to run the query with this segment, I get an error "Segment is not supported in the API."

MarkEdmondson1234 commented 8 years ago

The point of using the query explorer is its made by Google, so if it doesn’t work there it won't work anywhere, so you can quickly modify it until it is.

The first date of visit isn’t recorded by default in GA. You’ll need to put it in a custom dimension if you want it.

The best you could do is count the number of sessions of new visitors on 2015-08-03. Thats done using this API call: https://ga-dev-tools.appspot.com/query-explorer/?start-date=2014-08-03&end-date=2014-08-03&metrics=ga%3Asessions&dimensions=ga%3AuserType&filters=ga%3AuserType%3D%3DNew%20Visitor

jdeboer commented 8 years ago

Hi @omarcheek , you mentioned that when you tried using ga:dateOfSession in your segment definition it did not work. Did you receive an error message? Or did this not produce the result you were expecting? It would be good to know a bit more about the issue you had as I think it sounds like ga:dateOfSession is what you need. What was the command you entered? What was the error message you received?

omarcheek commented 8 years ago

@jdeboer When I try to execute this script: Gaid ="ga:111111" start_date = "2015-08-24" end_date = "2015-08-30"

test

ga.new_source= ga$getData(Gaid, batch = TRUE, walk = TRUE, start_date, end_date, metrics = "ga:screenViews", dimensions = "ga:screenName", sort = "", filters = "", segment = "users::condition::ga:userType==New%20Visitor;ga:date==2015-08-25")

I recieve the following error:
Error in .self$refreshToken() : could not find function "POST"

When I use ga:dateOfSession instead of ga:date, I get the same error


Later I found working solution for my case https://ga-dev-tools.appspot.com/query-explorer/?start-date=2015-08-01&end-date=2015-08-21&metrics=ga%3Asessions&dimensions=ga%3Adate&segment=users%3A%3Asequence%3A%3A%5Ega%3AsessionCount%3D%3D1%3BdateOfSession%3C%3E2015-08-05_2015-08-05%3B-%3E%3Ega%3AsessionDurationBucket%3E600&samplingLevel=HIGHER_PRECISION&start-index=1&max-results=10000

when I tried to use the same segment in RStudio, I got the same error. So I think there is something wrong with RGA.

I do need this report in Rstudio. Basicly, this report is Churn Rate for my users. Please help me, guys.

mattpolicastro commented 8 years ago

@omarcheek Have you tried clearing your API token? A failure to refresh would indicate something has gone awry. Unload/reload the package, and remove your current access token from the environment and, if stored as a file on your system, delete it.

omarcheek commented 8 years ago

@mattpolicastro Yes. I tried. nothing helped. Try to run any of 3 scripts i mentioned above. Do they run correctly on your PC ?

mattpolicastro commented 8 years ago

I'm unable to get any of them working, even in the Query Explorer. Set up the segment you are after in GA's dashboard, use ga$getSegments() to retrieve a data.frame of your available segments, then proceed. For example, I was able to roughly approximate your target segment as the following: sessions::condition::ga:userType==New Visitor;condition::dateOfSession==2015-08-25.

omarcheek commented 8 years ago

@mattpolicastro

it is strange, but I get the same error Error in .self$refreshToken() : could not find function "POST" running ga$getSegments()

I will try to reistall RGA. are there any instructions to do it ?

mattpolicastro commented 8 years ago

If you are using RStudio, then the Packages view allows you to uninstall local packages.

However, this discussion seems entirely out of scope of RGA, and would be better on StackOverflow or similar.

MarkEdmondson1234 commented 8 years ago

Make sure you are talking about the same package too, this is the github for rga() - RGA() is this one: https://cran.r-project.org/web/packages/RGA/index.html

mattpolicastro commented 8 years ago

@MarkEdmondson1234 ah, thank you. I didn't realise there was a package going by all-caps as well.