def get_google_analytics(self, GA_items):
        ga = Gahelper(self.config)
        print("GA_items in get_google_analytics is ", GA_items)
        if not GA_items.get('standard_metrics'):
            f = {'img': "", 'txt': ""}
        if not GA_items.get('start'):  # start is missing
            if GA_items.get('end'):  # end is not missing
                f = {'img': "", 'txt': "start missing"}
            else:
                f = {'img': "", 'txt': "date range is missing."}
        else:  # start is not missing
            if not GA_items.get('end'):  # end is missing
                f = {'img': "", 'txt': "end missing"}
            else:
                metrics = GA_items.get('standard_metrics', [])
                dimensions = GA_items.get('standard_dims', [])
                if len(GA_items.get('start')) == 1:
                    start_date = str(GA_items.get('start')[-1])
                    end_date = str(GA_items.get('end')[-1])
                else:
                    # if there are more than one pair of start and end, which one is right? Or need to combine all/both pairs?
                    # for the moment, use the last one. It is more likely to be the right one. For example, how many sessions per month in 2017? Then ['month', '2017'] will be returned. use the last one '2017'.
                    start_date = str(GA_items.get('start')[-1])
                    end_date = str(GA_items.get('end')[-1])
                print(metrics, dimensions, start_date, end_date)

                report = ga.get_report(metrics, dimensions, start_date,
                                       end_date)
                print(tabulate(report, headers='keys', tablefmt='psql'))
                f = format_dataframe(self.s3, self.bucketname, report, metrics,
                                     dimensions, start_date, end_date)
                print(f)
        return f
示例#2
0
    def get_google_analytics(self,GA_items):
        ga = Gahelper(self.config)
        metrics = GA_items.get('standard_metrics', [])
        dimensions = GA_items.get('standard_dims',[])
        start_date = str(GA_items.get('start'))
        end_date = str(GA_items.get('end'))
        print(metrics, dimensions,start_date,end_date)

        report = ga.get_report(metrics, dimensions, start_date, end_date)
        print(tabulate(report, headers='keys', tablefmt='psql'))
        f = format_dataframe(self.s3, self.bucketname, report, metrics, dimensions, start_date, end_date)
        print(f)
        return f