Version: | 0.7-1 |
Date: | 2018-10-23 |
Title: | API for Mixpanel |
Depends: | R (≥ 3.2.0) |
Description: | Provides an interface to many endpoints of Mixpanel's Data Export, Engage and JQL API. The R functions allow for event and profile data export as well as for segmentation, retention, funnel and addiction analysis. Results are always parsed into convenient R objects. Furthermore it is possible to load and update profiles. |
Imports: | jsonlite, uuid, RCurl, base64enc |
License: | MIT + file LICENSE |
URL: | https://github.com/ploner/RMixpanel, http://www.mixpanel.com |
NeedsCompilation: | no |
Packaged: | 2018-10-23 16:21:04 UTC; meinhard |
Author: | Meinhard Ploner [aut, cre, cph], ProSiebenSat.1 Digital GmbH [cph], BCG Digital Ventures GmbH [cph] |
Maintainer: | Meinhard Ploner <meinhard.ploner@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2018-10-23 16:50:03 UTC |
API for Mixpanel
Description
Provides an interface to many endpoints of Mixpanel's Data Export, Engage and JQL API. The R functions allow for event and profile data export as well as for segmentation, retention, funnel and addiction analysis. Results are always parsed into convenient R objects. Furthermore it is possible to load and update profiles.
Details
The DESCRIPTION file:
Package: | RMixpanel |
Version: | 0.7-1 |
Date: | 2018-10-23 |
Title: | API for Mixpanel |
Authors@R: | c( person("Meinhard", "Ploner", role=c("aut", "cre", "cph"), email="meinhard.ploner@gmail.com"), person("ProSiebenSat.1 Digital GmbH", role="cph"), person("BCG Digital Ventures GmbH", role="cph") ) |
Depends: | R (>= 3.2.0) |
Description: | Provides an interface to many endpoints of Mixpanel's Data Export, Engage and JQL API. The R functions allow for event and profile data export as well as for segmentation, retention, funnel and addiction analysis. Results are always parsed into convenient R objects. Furthermore it is possible to load and update profiles. |
Imports: | jsonlite, uuid, RCurl, base64enc |
License: | MIT + file LICENSE |
URL: | https://github.com/ploner/RMixpanel, http://www.mixpanel.com |
Author: | Meinhard Ploner [aut, cre, cph], ProSiebenSat.1 Digital GmbH [cph], BCG Digital Ventures GmbH [cph] |
Maintainer: | Meinhard Ploner <meinhard.ploner@gmail.com> |
Index of help topics:
RMixpanel-package API for Mixpanel createDateSequence Generate And Normalize Sequence Of Dates. eventsJson2RMatrix Convert Events Exported From Mixpanel API To R Matrix merge.matrix Merge Two Matrices mixpanelCreateAccount Create Mixpanel Account mixpanelGetAddiction Addiction Report mixpanelGetData General Method For Mixpanel API Requests mixpanelGetEvents Get Events From Mixpanel API mixpanelGetEventsForProfiles Get Events For Specified Profiles mixpanelGetEventsFromFiles Get Events From Files mixpanelGetFunnel Funnel mixpanelGetFunnelList Funnel List mixpanelGetProfiles Get Profiles From Mixpanel API mixpanelGetProfilesCount Get Profiles Count From Mixpanel API mixpanelGetRetention Retention Report mixpanelGetSegmentation Segmentation Report mixpanelJQLQuery Query the Mixpanel JQL API mixpanelUpdateProfile Update Mixpanel Profile plot.retention Plot Retention Rates print.retention Print Retention Matrix profilesJson2RMatrix Convert Profiles Exported From Mixpanel API To R Matrix.
The package provides access to the Mixpanel API. It allows to read raw data as well as to retrieve retention, addiction and segmentation data. Furthermore it is possible to load and update profiles.
Author(s)
NA Maintainer: NA
References
https://mixpanel.com/help/reference/data-export-api
Generate And Normalize Sequence Of Dates.
Description
Generate a range of dates and normalize it. Used by other methods of this package.
Usage
createDateSequence(from, to=from)
Arguments
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
Value
Array of daily dates in format yyyy-mm-dd as needed for use in Mixpanel's API.'
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api
Convert Events Exported From Mixpanel API To R Matrix
Description
Convenience method to convert from pseudo json of Mixpanel's export API to R matrix holding events.
Usage
eventsJson2RMatrix(jsonData, select = TRUE)
Arguments
jsonData |
Result of request to Mixpanel's Export API. |
select |
If |
Details
Ths helper function takes a json result as of the Mixpanel Export API and creates an R matrix holding the data. Array event properties are collapsed using a dash ('-') as separator.
Value
A character matrix showing one event per line. The first column represents the name of the event, the other column the event properties.
Author(s)
Meinhard Ploner
See Also
Merge Two Matrices
Description
Merge two matrices by common column names. Resulting matrix includes all data. Empty cells are filled with NA's.
Usage
## S3 method for class 'matrix'
merge(x, y, ...)
Arguments
x |
First matrix to be merged. |
y |
Second matrix to be merged. |
... |
Not used. |
Value
A matrix resulting from a join of the 2 matrices.
Author(s)
Meinhard Ploner
Create Mixpanel Account
Description
Create object holding meta data of a Mixpanel project.
Usage
mixpanelCreateAccount(name, token, key, secret, customEvents,
mongoDBname, dataPath, RDataPath)
Arguments
name |
Can be arbitrary. |
token |
API token of Mixpanel project. |
key |
API key of Mixpanel project. |
secret |
API secret of Mixpanel project. |
customEvents |
If you have custom events, add a |
mongoDBname |
Optional. Name of data base for usage in mongoDB. Used in future versions of the package. |
dataPath |
Optional. Path to store raw data of events and people. |
RDataPath |
Optional. Path to store R rda files. |
Value
An object holding all the values specified as parameters.
Author(s)
Meinhard Ploner
See Also
mixpanelGetEvents
,
mixpanelGetProfiles
,
mixpanelGetSegmentation
,
mixpanelGetRetention
Addiction Report
Description
Get matrix of addiction data from Mixpanel API.
Usage
mixpanelGetAddiction(account, event, from, to, unit, percentages, addictionUnit, ...)
Arguments
account |
A mixpanel account, as created by |
event |
Event name. If empty, all events are returned. |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
unit |
Defaults to 'day'. |
percentages |
Output as counts or percentages? |
addictionUnit |
Sub time unit for addiction calculation. |
... |
Additional arguments to Mixpanel API. |
Value
Matrix consisting of one row for each cohort. The first column holds the cohort sizes, the following columns the number of profiles having tracked events within the specified time interval.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#retention
See Also
General Method For Mixpanel API Requests
Description
This method handles the authentication and download of data from the Mixpanel API as well as data persistance. The method is used by many of the more specialized methods of this package.
Usage
mixpanelGetData(account, method="export/", args, validitySeconds=60, verbose=TRUE,
fileName="", data=FALSE, retryCount=0, encoding="UTF-8")
Arguments
account |
A mixpanel account, as defined in |
method |
API method (route). |
args |
Arguments as described in https://mixpanel.com/help/reference/data-export-api. |
validitySeconds |
Expiration of API request. |
verbose |
If |
fileName |
File name to persist data (defaults to './temp.txt'). If supplied, account$dataPath is used as path. |
data |
If |
retryCount |
How many times a failed request should be retried? |
encoding |
JSON Encoding. Default is UTF8. |
Value
If data==TRUE
, the method returns the response of the API request (raw character vector). Otherwise nothing is returned.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelGetData(account, method="funnels/list/", args=list(), data=TRUE)
## End(Not run)
Get Events From Mixpanel API
Description
Get a matrix filled with event data from the Mixpanel API.
Usage
mixpanelGetEvents(account, event, from, to = from, daysPerBlock = 10,
select = TRUE, verbose = TRUE, df = FALSE, encoding="UTF-8", ...)
Arguments
account |
A mixpanel account, as defined in |
event |
Array of event names. If empty, all events are returned. |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
daysPerBlock |
Data is downloaded in blocks of fixed size. |
select |
If |
verbose |
If |
df |
Clean data and return |
encoding |
JSON Encoding. Default is UTF8. |
... |
Additional arguments to be included in the Mixpanel API request. E.g. where = "properties[\"$os\"]==\"iPhone OS\""). See also https://mixpanel.com/help/reference/data-export-api#events. |
Value
A character matrix showing one event per line. The first column represents the name of the event, the other column the event properties.
Author(s)
Meinhard Ploner
See Also
mixpanelGetProfiles
,
mixpanelGetEventsForProfiles
Get Events For Specified Profiles
Description
Get a matrix filled with event data for specified people profiles.
Usage
mixpanelGetEventsForProfiles(account, distinctIDs, from, to, verbose,
encoding="UTF-8", ...)
Arguments
account |
A mixpanel account, as defined in |
distinctIDs |
Array of profile IDs. |
from |
Date in format yyyy-mm-dd, where month number starts with 0. |
to |
Date in format yyyy-mm-dd, where month number starts with 0. |
verbose |
Parameter passed to |
encoding |
JSON Encoding. Default is UTF8. |
... |
List of additional arguments being included in the Mixpanel API request. E.g. limit=5, ... |
Value
A character matrix showing one event per line. The first column represents the name of the event, the other column the event properties.
Author(s)
Meinhard Ploner
See Also
mixpanelGetProfiles
,
mixpanelGetEvents
Get Events From Files
Description
Get an R matrix filled with event data using data saved into files.
Usage
mixpanelGetEventsFromFiles(account, from, to, eventNames=c(),
select=TRUE, blocksize=500000, df = FALSE, verbose=TRUE)
Arguments
account |
A mixpanel account, as defined in |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
eventNames |
If an array of event names, only these are returned by the method. |
select |
If |
blocksize |
Block size for reading files from disk. |
df |
Clean data and return |
verbose |
If |
Value
A character matrix showing one event per line. The first column represents the name of the event, the other column the event properties.
Author(s)
Meinhard Ploner
See Also
Funnel
Description
Get funnel data from Mixpanel API. Custom events are names accordingly, if account
is set up correctly using mixpanelCreateAccount.
Usage
mixpanelGetFunnel(account, funnel, from, to=from, verbose=TRUE, ...)
Arguments
account |
A mixpanel account, as defined in |
funnel |
Either name or ID of the funnel. See also |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
verbose |
If |
... |
Additional arguments to Mixpanel API. E.g. |
Value
Object of class funnel
including a list of data.frame
's representing the funnels for each time frame.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#funnels
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelGetFunnel(account, "Funnel001", from=20161001, to=20161101, unit="week")
## End(Not run)
Funnel List
Description
Get list of all defined funnels from Mixpanel API.
Usage
mixpanelGetFunnelList(account, verbose=TRUE)
Arguments
account |
A mixpanel account, as defined in |
verbose |
If |
Value
A data.frame with 1 row for each funnel. Columns include
funnel_id |
ID of the funnel. |
name |
Name of the funnel. |
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#funnels
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelGetFunnelList(account)
## End(Not run)
Get Profiles From Mixpanel API
Description
Get a matrix filled with profiles (also called 'users' or 'people') taken from the Mixpanel People API.
Usage
mixpanelGetProfiles(account, where="", select, maxPage=100000, verbose=TRUE)
Arguments
account |
A mixpanel account, as defined in |
where |
Expression, see https://mixpanel.com/help/reference/data-export-api#segmentation-expressions. |
select |
If |
maxPage |
The API delivers usually about 1000 users per page. Setting this parameter can limit the response for testing purposes. A value of 9 returns page 0 to page 9, i.e. 10000 profiles. |
verbose |
If |
Value
A character matrix showing one profile per line. The first column represents the distinct ID of the profile, the other column the profile properties.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#people-analytics
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
profiles = mixpanelGetProfiles(account, where='properties["KPI1"] > 1.32',
select=c("KPI1", "KPI2"))
print(profiles)
## End(Not run)
Get Profiles Count From Mixpanel API
Description
Get the number of profiles (also called 'users' or 'people') conforming to the requested query from the Mixpanel People API.
Usage
mixpanelGetProfilesCount(account, where = "", verbose=TRUE)
Arguments
account |
A mixpanel account, as defined in |
where |
Expression, see https://mixpanel.com/help/reference/data-export-api#segmentation-expressions. |
verbose |
If |
Value
The number of profiles conforming to the query.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#people-analytics
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelGetProfilesCount(account, where='properties["KPI1"] > 1.32')
## End(Not run)
Retention Report
Description
Get retention data from Mixpanel API. The resulting object can be printed nicely using print.retention
.
Usage
mixpanelGetRetention(account, event, from, to, unit, retentionType,
intervalCount, verbose=TRUE, ...)
Arguments
account |
A mixpanel account, as defined in |
event |
Event name. If empty, all events are returned. |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
unit |
Defaults to 'day'. |
retentionType |
|
intervalCount |
Number of intervals per cohort to return. |
verbose |
If |
... |
Additional arguments to Mixpanel API. E.g. |
Value
Object of class retention
including
dates |
Start dates of each cohort. |
cohortCount |
Size of cohorts (people count). |
retainCount |
Number of retained people. |
retainPerc |
Percentage of retained people. |
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#retention
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelGetRetention(account, born_event="AppInstall", event="WatchedItem",
from=20150701, to=20151101, unit="week")
## End(Not run)
Segmentation Report
Description
Get a matrix of events segmented by 1 or 2 properties. Event data is taken from the Mixpanel Segmentation API.
Usage
mixpanelGetSegmentation(account, event, from, to, unit, type, on, action, verbose, ...)
Arguments
account |
A mixpanel account, as defined in |
event |
Event name. If empty, all events are returned. Custom events are supported, if |
from |
Start date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
to |
End date in either format <"yyyy-mm-dd"> or <yyyymmdd>. Inclusive. |
unit |
Defaults to 'day'. |
type |
This can be "general", "unique", or "average". |
on |
Array of up to 2 property names for segmentation. An empty array returns un-segmented counts. E.g. 'properties["$os"]' |
.
action |
Could be "sum" or "average". If given, 1st property listed in |
verbose |
If |
... |
Additional arguments to Mixpanel API. See also https://mixpanel.com/help/reference/data-export-api#segmentation. |
Value
2 or 3-dimensional array showing event counts. The first dimension represents the time in the specified unit. The other dimension(s) are determined by the segmention properties. Usually the Mixpanel API does not return more than 60 or 100 slots per segmentation property. For more data, use the events API (mixpanelGetEvents
).
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#segmentation
Query the Mixpanel JQL API
Description
This method performs a JQL Query with some custom script as parameter. The query string can be given either as character vector or saved into a file and passed via file name.
Usage
mixpanelJQLQuery(account, jqlString, jqlScripts, paths=".", columnNames, toNumeric=c())
Arguments
account |
A mixpanel account, as defined in |
jqlString |
JQL script as string. |
jqlScripts |
List of JQL script file names. |
paths |
Paths to search JS files. |
columnNames |
Column names for the resulting data.frame. Optional. |
toNumeric |
Column indices which should be converted to numeric. Optional. |
Value
If data==TRUE
, the method returns the response of the API request (raw character vector). Otherwise nothing is returned.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/jql
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
## Simple query: number of events for each 'distinct_id'.
jqlQuery <- '
function main() {
return Events({
from_date: "2016-01-01",
to_date: "2016-12-31"
})
.groupByUser(mixpanel.reducer.count())
}'
res <- mixpanelJQLQuery(account, jqlQuery,
columnNames=c("distinctID", "Count"), toNumeric=2)
hist(res$Count)
## End(Not run)
Update Mixpanel Profile
Description
Update Mixpanel profiles (also called 'users' or 'people') using the Mixpanel Engage API.
Usage
mixpanelUpdateProfile(account, distinctID, data,
updateLastSeen=FALSE, updateLocation=FALSE, retryCount=100)
Arguments
account |
A mixpanel account, as defined in |
distinctID |
A distinct ID, identifying the profile. Could be extracted by calling |
data |
JSON dictionary with property names and values. See Mixpanel documentation or example below. |
updateLastSeen |
If |
updateLocation |
If |
retryCount |
Applied if the HTTP request fails. |
Value
None.
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/http#people-analytics-updates
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
mixpanelUpdateProfile(
account,
"11b9c243-4ea3...",
data=list(
"$set"=list(day=jsonlite::unbox(12),
month=jsonlite::unbox(3),
"$name"=jsonlite::unbox("Dummy name")),
"$setOnce"=list(installYear=2016),
"$unset"=c("oldProp1", "oldProp2"),
"$union"=list(month=10:12)
## "$delete": "" ## !!! Delete user. !!!
)
)
## End(Not run)
Plot Retention Rates
Description
Plot Retention Rates as a line chart. Multiple chart types are available.
Usage
## S3 method for class 'retention'
plot(x, type="all", percentages=TRUE, omitLast=TRUE,
colors, durations, y, ...)
Arguments
x |
Object of class |
type |
Character vector. If "all", all chart types are plotted. Valid values are |
percentages |
Use retention counts or percentages? Default is |
omitLast |
Omit last value per series? Useful for Mixpanel data, because last value is usually based on partial data! |
colors |
Colors for lines. Optional. |
durations |
Selected Durations (index). Default is c(1, 2, 5, 10). |
y |
Not used. |
... |
Not used. |
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#retention
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
ret = mixpanelGetRetention(account, born_event="AppInstall", event="WatchedItem",
from=20150701, to=20151101, unit="week")
par(mfrow=c(2, 2))
plot(ret, type="all")
par(mfrow=c(1, 1))
## End(Not run)
Print Retention Matrix
Description
Print Retention Matrix as counts or percentages.
Usage
## S3 method for class 'retention'
print(x, percentages=TRUE, silent=FALSE, ...)
Arguments
x |
Object of class |
percentages |
Boolean. Indicates if retain counts should be shown as percentages or raw count. default is |
silent |
If |
... |
Not used. |
Value
Matrix consisting of one row for each cohort. The first column holds the cohort sizes, the following columns the counts for subsequent periods. If percentages
is TRUE
, the counts are percentages (except first column).
Author(s)
Meinhard Ploner
References
https://mixpanel.com/help/reference/data-export-api#retention
See Also
Examples
## Not run:
## Fill in here the API token, key and secret as found on
## www.mixpanel.com - Account -> Projects.
account = mixpanelCreateAccount("ProjectName",
token="c12g3...",
secret="168e7e...",
key="543c55...")
ret = mixpanelGetRetention(account, born_event="AppInstall", event="WatchedItem",
from=20150701, to=20151101, unit="week")
print(ret, percentages=FALSE)
print(ret, percentages=TRUE)
## End(Not run)
Convert Profiles Exported From Mixpanel API To R Matrix.
Description
Convenience function to convert json result of engage API to R matrix holding people data.
Usage
profilesJson2RMatrix(jsonData, select = TRUE)
Arguments
jsonData |
Result of request to Mixpanel's Engage API. |
select |
If |
Details
Ths helper function takes a json result as of the Mixpanel Engage API and creates a R matrix holding the data. Array user properties are collapsed using a dash ('-') as separator.
Value
A character matrix showing one profile per line. The first column represents the distinct ID of the profile, the other column the profile properties.
Author(s)
Meinhard Ploner