2 Replies Latest reply: Feb 17, 2016 1:43 PM by Wagner Morandi RSS

    Google Analytics in a Loop - Issue

      Hi To All!

      Im having a problem in Google Analytics loading datas.


      As you know, the Google Api have some limits and you have to parse loading to extract datas.

      So, you have two ways to do it. First one its to parse loading in month but repeating the script part of loading and changing the Date_Start and the Date_End.

      The problem its that the script will grow up every month and you have superfluous code.


      The other way its to implement a Loop and using variables to build the dates. Code looks like this:



      set año = 2012;

      set mes = 12;

      set pasa = 0;


      for año = 2012 to 2011 step -1

          for mes = 12 to 1 step -1


              set gDateStart = '$(año)-$(mes)-01';

              set gDateEnd = '$(año)-$(mes)-28';


              // Dimensions & Metrics Reference


              SET gDimensions='ga:date,ga:campaign,ga:medium,ga:adGroup';

              SET gMetrics='ga:impressions,ga:adClicks,ga:adCost,ga:CPM';


              EXECUTE java -jar GoogleAnalyticsClient-20100623.jar -u $(gUserName) -p $(gPassword) -f $(gProfileId) -d $(gDimensions) -m $(gMetrics) -s $(gDateStart) -e $(gDateEnd) -o $(VPath)visitsSPR_AW.csv --max-results=10000000;




                  ga:date as ad:date,

                  Year(ga:date) & '-' & Month(ga:date) as AñoMes_ad:date,

                  Week(ga:date) as Semana_ad_date,

                  WeekDay(ga:date) as WeekDay_ad:date,

                  ga:campaign as ad:campaign,

                  ga:medium as ad:medium,

                  if (ga:medium = 'cpc' or ga:medium = 'ppc'     or

                      ga:medium = 'cpa' or ga:medium = 'cpm' or

                      ga:medium = 'cpv'or ga:medium = 'cpp', 'Trafico_Pago', 'Organico') as ad:Clasif_Trafico,

                  ga:adGroup as ad:adGroup,

                  ga:impressions as ad:impressions,

                  ga:adClicks as ad:adClicks,

                  num#(ga:adCost, '#.#', '.' , ',' ) as ad:adCost,

                  num#(ga:CPM, '#.#', '.' , ',' ) as ad:CPM,

                  'example' as ad:perfil



              (txt, codepage is 1252, embedded labels, delimiter is ',', msq);


              for I=1 to 10000

                  set pasa=0;







      Whats the problem? Well, the problem its that it works repeating the code... and it birngs datas every month. But, into the loop only returns datas a few months, not all.


      Can Someone had the same problem?

      Thanks to All!!

      Regards. Germán