Documente Academic
Documente Profesional
Documente Cultură
Since subscription payments (other than the first payment) are not triggered by users’
action, they need to be tracked server side.
When a user first sign up, assign him a unique user id.
You can use login id as user id.
Just make sure that the id does not contain Personally Identifiable data like name, email
address, IP address etc.
Any data that allows Google to personally identify an individual or data that permanently
identifies a particular device (such as a unique device identifier, if such an identifier
cannot be reset) is Personally Identifiable data.
If you upload any data that allows Google to personally identify an individual, your
Google Analytics account can be terminated, and you may lose your Google Analytics
data as this is against Google Terms of Service.
The user id is used to sum up the recurring revenue by a user.
When a user make the first initial purchase you can set a unique user id for him and
note down his transaction ID.
For second and subsequent purchases, send transaction data (with unique transaction
ID) to Google Analytics via measurement protocol whenever you process payment.
When a subscription stops then stop sending the transaction data via measurement
protocol for a particular user.
In order to make an HTTP request to the GA server (for sending the raw hit data
directly), you need to format your HTTP request according to the measurement
protocol.
This formatted HTTP request is called the measurement protocol request.
Here is how the measurement protocol request looks like:
The measurement
protocol request is made up of: user agent, transport and payload data:
Payload data is the data
you send to Google Analytics server using the measurement protocol.
In other words, the payload data is the data which has been formatted according to
Measurement Protocol.
Following is an example of payload data:
v=1&tid=UA-123456-2&cid=36009a59-2a05-49e7-b826-
2b884d0f935b&t=pageview&dp=%2Fhome
parameter1¶meter2¶meter3
or
key1=value1&key2=value2&key3=value3
Source: https://developers.google.com/analytics/devguides/collection/protocol/v1/devgui
de
Click on the link ‘view this hit in the measurement protocol hit builder‘ to see how
this hit actually looks like.
All values you sent via measurement protocol to GA, must be both UTF-8 encoded
and URL encoded.
For example, / is encoded to %2F
If the values are not encoded correctly then they will be replaced with unicode
replacement character xFFFD
Note (1): You can learn more about URL encoding from
here: http://www.w3schools.com/tags/ref_urlencode.asp
Note (2): All protocol parameters must be set on the same line. They should not have
any spaces between them. Comments are not allowed in protocol parameters.
The measurement protocol supports following data types for the values in the
‘key = value’ pairs of the payload data:
1. Integer – used to represent a number
2. Text – used to represent a string
3. Boolean – used to represent a boolean value (true or false)
4. Currency – used to represent the total value of a currency in up to 6 decimal points.
Transport defines where and how to send the payload data.
Following is an example of transport:
POST http://www.google-analytics.com/collect
You can send payload data by either using the GET method or POST method.
Google recommends using POST method, as then you can send larger payload data to
GA server.
The location of the GA server is: https://www.google-analytics.com
This is where we send the payload data.
The payload data need to be URL encoded, if you are making HTTP POST request to
the GA server.
The size of Payload data, if you are making HTTP POST request to the GA server can
be maximum of 8191 Bytes.
However, if you make HTTP GET request to the GA server, then the size of payload
data cannot be more than 2000 Bytes.
Write a script to make the following similar HTTP POST request to the GA server in
order to send the payload data:
User-Agent: user_agent_string
POST https://www.google-analytics.com/collect?payload_data
Use measurement protocol hit builder to validate hits: https://ga-dev-
tools.appspot.com/hit-builder/
Note: GA hit builder use only one URL endpoint, /collect
#2 Your application must convert the retrieved data into the payload data according to
the measurement protocol:
#3 Your application must make a HTTP POST request to the end point (Google
Analytics server) in order to send the payload data to the GA server. The HTTP request
should be made up of user agent, transport and payload data:
When GA receives the HTTP request from your application, it try to process the payload
data in the HTTP request.
If GA successfully processes the payload data then its server will send 2XX response
code back to your application:
If GA is not successful, in processing the payload data, then its server does not send
any error code back to your application.
As you create monthly invoices for our customers, you could have a request sent
through the measurement protocol which specifies the invoice details as soon as the
payment comes in as successfully processed.
Assign a unique transaction ID for each new transaction for a particular user.
If you update the original transaction with new value then you won’t be able to see
individual transactions for a particular user over time.
If you don’t assign an unique transaction ID for each new transaction for a particular
user then you will have duplicate transaction issues.
You can segment the data by user id and should be able to see all of the transactions
for a particular user in the user explorer report in the user id view :
In addition to that you can create a custom dimension and pass user id value to it.
Then you create a user id custom segment.
By doing that you can segment any GA report by user id custom segment and do
detailed analysis for a particular user.
If some of your customers book well in advance, say 2 months in advance then send
transaction data via measurement protocol after 2 months to maintain the accuracy of
the sales data.
Record sales only on the day of the actual sales whether the sales is user
generated or generated by you in response to billing.
For example,
Now if you reverse the transaction on Monday, then the total sales amount for Monday
would be reported to be: $500 – $200 = $300
If you reverse the same transaction on say Tuesday, thenthe total sales amount for
Monday would remain $500
the total sales amount for Tuesday would be: Total website sales for Tuesday – $200