Skip to content

Latest commit

 

History

History
462 lines (328 loc) · 17.5 KB

user-manual.adoc

File metadata and controls

462 lines (328 loc) · 17.5 KB

GoogleAnalytics Connector

Overview

The GoogleAnalytics connector was implemented using java and consuming Google Analytics core V3 API. The connector exposes Generate Report operation.

Prerequisites

Application/Service Version

Mule Runtime

4.x

Google Analytics Core

Reporting API V3

Java

1.8 and later

This document assumes that you are familiar with Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

You need login credentials to test your connection to your target resource.

For hardware and software requirements and compatibility information, see the Connector Release Notes.

To use this connector with Maven, view the pom.xml dependency information in the Dependency Snippets in Anypoint Exchange.

What’s New in this Connector

  1. Support for Mule4 has been added.

How to Configure Service Account Authorization.

Initial Steps to generate clients secrets file from service account:

  1. Register your application in the Google API Console.

  2. Authorize access to Google Analytics Data.

  3. Go to Google API Console Credentials Page and click Select a project, then NEW PROJECT, and enter a name for the project, and optionally, edit the provided project ID. Click Create.

  4. To create a Client ID using an Service Account go to Service account page in Google API Console select the project if prompted.

  5. In the Create service account window, type a name for the service account, and select Furnish a new private key. If you want to grant G Suite domain-wide authority to the service account, also select Enable G Suite Domain-wide Delegation. Then click Save.

  6. When prompted for the Key type select JSON, and save the generated key as client_secrets.json.

  7. Add service account to Google Analytics account by The newly created service account will have an email address, <projectId>-<uniqueId>@developer.gserviceaccount.com; Use this email address to add a user to the Google analytics account you want to access via the API.

  8. Go back to Anypoint Studio and in a Anypoint Mule Application create a new GoogleAnalytics Connector configuration.

  9. Fill the Json File Path , Application Name .

  10. To get the Application name login to your Google API console and navigate to credentials and then to OAuth Consent Screen you can find Application name.

  11. Save this Application name for usage.

    Json File Path xxxxx.json

    Application Name

    xxxxxxxxxxx

    Save configuration. Your configuration should look like:

    <google-analytics:config name="Google_Analytics_Config" doc:name="Google Analytics Config" doc:id="9cb86789-1ca1-4eda-b007-e2ca4bd63a6b" >
    		<google-analytics:connection jsonFilePath="xxxxxx.json" applicationName="#['xxxxxxx']"/>
    	</google-analytics:config>
    Google Aanalytics Config
  12. To authorize a user in your Mule application, you should create a flow like the following calling the "authorize" operation:

    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="xxxxx" >
    		<http:listener-connection host="localhost" port="8081" />
    	</http:listener-config>
    	<flow name="generateReportFlow" doc:id="xxxxxxxxxxx" >
    		<http:listener doc:name="Listener" doc:id="xxxxxxxxxxx" config-ref="HTTP_Listener_config" path="/test"/>
    		<google-analytics:generate-report doc:name="Generate report" doc:id="xxxxxxxxxxxxx" config-ref="Google_Analytics_Config"/>
    
    </flow>
    Then in a browser enter to http://localhost:8081/test and authorize your user.

See Also

Operations:

Generate report:

Generate report is core operation of the connector which is responsible for getting google analytics data .

Input Parameters for generate report:

Input Parameters for generate report:

Id : String(required)

The unique table ID is the Analytics view (profile) ID for which the query will retrieve the data.

Example: UA-xxxxx-xxx

Find your Google Analytics ID

. Create an Google Analytics Account.
. Sign in to your Account and click Admin
. Select an account from the menu in the ACCOUNT column.
. Select a property from the menu in the PROPERTY column.
. Under PROPERTY, click Tracking Info > Tracking Code. Your Google Analytics ID is displayed at the top of the page.

Start-Date : String(required)

Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date (e.g., today, yesterday, or NdaysAgo where N is a positive integer).

Values must match [0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo).

The earliest valid start-date is 2005-01-01. There is no upper limit restriction for a start-date. Relative dates are always relative to the current date at the time of the query and are based on the timezone of the view (profile) specified in the query.

Google analytics connector has a facility to select value from the dropdown list or user can give the date manually according to the matching pattern.

Example: today,7daysAgo,2019-01-30

  1. Selecting value from the dropdown.

    start date 1
  2. If user want to give start date manually.

start date 2

End-date : String(required)

All Analytics data requests must specify a date range. If you do not include start-date and end-date parameters in the request, the server returns an error. Date values can be for a specific date by using the pattern YYYY-MM-DD or relative by using today, yesterday, or the NdaysAgo pattern. Values must match [0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo). The earliest valid end-date is 2005-01-01. There is no upper limit restriction for an end-date. Relative dates are always relative to the current date at the time of the query and are based on the timezone of the view (profile) specified in the query.

Google analytics connector has a facility to select value from the dropdown list or user can give the date manually according to the matching pattern.

Example: today,7daysAgo,2019-01-30

Metrics : String(required)

Metrics are the actual numbers google analytics measures from your website . whether thats number of sessions , time on page or the bounce rate.

The aggregated statistics for user activity to your site, such as clicks or pageviews. If a query has no dimensions parameter, the returned metrics provide aggregate values for the requested date range, such as overall pageviews or total bounces. However, when dimensions are requested, values are segmented by dimension value. For example, pageviews requested with country returns the total pageviews per country. When requesting metrics, keep in mind.

  1. Any request must supply at least one metric; a request cannot consist only of dimensions.

  2. You can supply a maximum of 10 metrics for any query.

  3. Most combinations of metrics from multiple categories can be used together, provided no dimensions are specified

To know more about metrics access the link : metrics parameters

Building metrics query

  1. Click on the plus sign to build the query

    metrics 1
  2. Select metrics values from the dropdown list

    metrics 2
  3. Save the Selected values to build the query

metrics 3

+

<google-analytics:metrix-parameters>
<google-analytics:metrics-parameter value="Sessions" />
<google-analytics:metrics-parameter value="Bounces" />
</google-analytics:metrix-parameters>

Dimensions : String(optional)

A metrics are actual measurements produced on your website, dimensions are rules in which you can compile those measurements and convert them into actual, readable number relevant to your business.

To know more about Dimensions access the link : Dimensions parameters

Building dimension query

Building dimension query is similar to building metrics query adding the required values from the dropdown.

dimension

+

<google-analytics:dimension-parameters>
<google-analytics:dimension-parameter value="Browser" />
<google-analytics:dimension-parameter value="City" />
</google-analytics:dimension-parameters>

Sort : String(optional)

A list of dimensions and metrics indicating the sorting order and sorting direction for the returned data.

sort
  1. can be sorted either in ascending order or descending order. By default it has ascending order.

    <google-analytics:sortparms >
    <google-analytics:sort-parameter-type sortparamValue="Sessions" sortOrder="DESCENDING" />
    </google-analytics:sortparms>

Filters : String(optional)

The filters query string parameter restricts the data returned from your request. To use the filters parameter, supply a dimension or metric on which to filter, followed by the filter expression.

Building filter query

  1. To build a filter query click on the plus sign it opens a new window

    filter 1
  2. key parameters shows list of available filter metrics and dimensions values

    filter 2
  3. Operator parameter shows list of available operator in metrics like greaterThan or lessThan ..etc as shown in the table below

    Operator Description

    ==

    Equal to or exact match

    !=

    Not equal to or is not an exact match

    <

    Less than

    Less than or equal to

    >

    Greater Than

    >=

    Greater Than or equal to

    =@

    Contains substring

    !@

    Does not contain substring

    =~

    Contains a match for regular expression

    !~

    Does not contain a match for regular expression

    filter 3
  4. Value parameter is user defined and show be given by user and can be of integer or String.

    example: 1, United States...etc
  5. To use multiple filters we can combine them using AND , OR operation.

filter 4

+

  <google-analytics:filter-parameter>
	<google-analytics:filter-params>
<google-analytics:filter-parameter-type key="Sessions" operator="GreaterThan" value="1" operation="AND" />
<google-analytics:filter-parameter-type key="Country" operator="Equals" value="United States" operation="AND" />
</google-analytics:filter-params>
</google-analytics:filter-parameter>

Segment : String(optional)

A segment is a subset of your Analytics data. For example, of your entire set of users, one segment might be users from a particular country or city. Another segment might be users who purchase a particular line of products or who visit a specific part of your site.

Segments let you isolate and analyze those subsets of data, so you can examine and respond to the component trends in your business.

Building segment query

  1. To build a filter query click on the plus sign it opens a new window

    segment 1
  2. Segment key gives user to build an query using sessions or users condition.

    segment 2
  3. Segment type gives an option to select one or more conditions and/or sequences once you determine to use segment users or sessions.

    segment 3
  4. Segment filter gives list of dimensions and metrics values to choose from dropdown list.

    segment 4
  5. Segment Operator helps in choosing required operations to the segments. the list of operations available are shown below

Operator Description

==

Equal to or exact match

!=

Not equal to or is not an exact match

<

Less than

Less than or equal to

>

Greater Than

>=

Greater Than or equal to

<>

Between (value is between the given range)

[]

In list (value is one of the listed values)

=@

Contains substring

!@

Does not contain substring

=~

Contains a match for regular expression

!~

Does not contain a match for regular expression

  1. Segment value can be of type integer or string which is given by user.

    1. example: Chrome, 2 …​etc

  2. The complete query looks like

segment 5
  <google-analytics:segmentparameter >
	<google-analytics:segmentparams >
	<google-analytics:segment-parameter-type segmentKey="Users" segmentType="Condition" segmentFilter="Browser" segmentOpertor="EqualTo" segmentValue="Chrome" />
	</google-analytics:segmentparams>
	</google-analytics:segmentparameter>

SamplingLevel: String(optional)

The desired sampling levels. user can select from the following.

option value

DEFAULT

Returns response with a sample size that balances speed and accuracy.

FASTER

Returns a fast response with a smaller sample size.

HIGHER_PRECISION

Returns a more accurate response using a large sample size, but this may result in the response being slower.

Example: DEFAULT

Start-index : Integer(optional)

The first row of data to retrieve, starting at 1. Use this parameter as a pagination mechanism along with the max-results parameter.

Example: 10

Max-results : Integer(optional)

The maximum number of rows to include in the response.

Example: 100

Output : String(optional)

The desired output type for the Analytics data returned in the response. Acceptable values are json and dataTable(Default: json).

Example: json

Use Case: Studio

Create a Keyspace

  1. Create a new Mule Project in Anypoint Studio and fill in the Google Analytics credentials in src/main/resources/mule-app.properties.

    test flow
    config.jsonPath= <JSON_PATH>
    config.application_name=<APPLICATION_NAME>
  2. Drag an HTTP connector onto the canvas and leave the default values for Host and Port and set the path to /test.

  3. In the general tab fill the required query parameters by using valid Google Analytics ID , start-date, end-date and build Metrics Query.

  4. In the Advance tab you can use optional query parameters such as sorting, filter, dimensions , segments to get more precise data.

  5. Run the app. In a browser, use the following URL

Use Case: XML

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:google-analytics="http://www.mulesoft.org/schema/mule/google-analytics"
	xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/google-analytics http://www.mulesoft.org/schema/mule/google-analytics/current/mule-google-analytics.xsd">
   <configuration-properties file="mule-app.properties" />
	<google-analytics:config name="Google_Analytics_Config"
		doc:name="Google Analytics Config" doc:id="9cb86789-1ca1-4eda-b007-e2ca4bd63a6b">
		<google-analytics:connection jsonFilePath="${config.jsonPath}" applicationName="#${config.application_name}"/>
	</google-analytics:config>
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="6641e0fd-1048-470f-9e8b-f42a5e07310b" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<flow name="generateReportFlow" doc:id="c71676e1-21db-4aab-9745-1bc945381b69" >
		<http:listener doc:name="Listener" doc:id="7b3c8178-f8a1-48ea-95e7-2acfdb8ba7d6" config-ref="HTTP_Listener_config" path="/test"/>
		<google-analytics:generate-report doc:name="Generate report" doc:id="7d1826c8-1465-43e4-b5ca-c126f2b57381" config-ref="Google_Analytics_Config" profileId="#['xxxxxxx']" startDate="#['2019-01-15']" endDate="#['2019-02-15']">
			<google-analytics:metrix-parameters>
            <google-analytics:metrics-parameter value="Sessions" />
            <google-analytics:metrics-parameter value="Bounces" />
         </google-analytics:metrix-parameters>
         <google-analytics:dimension-parameters>
            <google-analytics:dimension-parameter value="Country"/>
         </google-analytics:dimension-parameters>
         <google-analytics:filter-parameter>
             <google-analytics:filter-params>
               <google-analytics:filter-parameter-type key="Sessions" operator="GreaterThan" value="1" operation="AND" />
            </google-analytics:filter-params>
         </google-analytics:filter-parameter>
         <google-analytics:segmentparameter >
				<google-analytics:segmentparams >
					<google-analytics:segment-parameter-type segmentKey="Users" segmentType="Condition" segmentFilter="Sessions" segmentOpertor="GreaterThan" segmentValue="1" />
				</google-analytics:segmentparams>
			</google-analytics:segmentparameter>
		</google-analytics:generate-report>
	</flow>
</mule>