@@ -27,6 +27,15 @@ to throw exceptions if something goes wrong. When left to the default value `Tru
2727(also see the `logger ` parameter).
2828
2929
30+ To get results of existing analyses stored in your Infinario project, you need to initialize the client
31+ with the Infinario project secret (found in the Overview screen) as the `secret ` keyword argument.
32+
33+ .. code-block :: python
34+
35+ client = Infinario(' 12345678-90ab-cdef-1234-567890abcdef' ,
36+ secret = ' fedcba09-8765-4321-fedc-ba0987654321' )
37+
38+
3039 Identifying the customer
3140------------------------
3241
@@ -92,16 +101,88 @@ will return::
92101
93102 '<img src="/my-awesome-banner-1.png" />'
94103
104+
105+ Analysis export
106+ ---------------
107+
108+ To export the entire result of an analysis, use the `export_analysis ` client method.
109+ It is necessary to authenticate during initialization of the client (see above).
110+ First argument is type of analysis (funnel, report, retention, segmentation), second argument is JSON object
111+ containing at least the ID of the analysis to export.
112+ Optional parameters include `format ` (one of `'native-json' ` (default), `'table-json' `, `'csv' `),
113+ `timezone ` (according to the IANA time zone database, default `'UTC' `)
114+ and `execution_time ` (UNIX timestamp specifying the upper bound of events to include, default is now).
115+
116+ .. code-block :: python
117+
118+ client = Infinario(' 12345678-90ab-cdef-1234-567890abcdef' ,
119+ secret = ' fedcba09-8765-4321-fedc-ba0987654321' )
120+
121+ data = client.export_analysis(' funnel' , {
122+ ' analysis_id' : ' 2f86608f-24f5-11e3-9950-c48508494cf5' ,
123+ ' format' : ' native-json' ,
124+ ' timezone' : ' UTC' ,
125+ })
126+
127+ The data could contain
128+
129+ .. code-block :: python
130+
131+ {
132+ " success" : true,
133+ " name" : " Conversion funnel" ,
134+ " steps" : [" First visit" , " Registration" , " First log in" , " Purchase" , " Payment" ],
135+ " total" : {
136+ " counts" : [48632 , 24120 , 20398 , 1256 , 1250 ],
137+ " times" : [- 1 , 680 , 4502 , 45 , 540 , 300 ],
138+ " metric" : 1987562
139+ },
140+ " drill_down" : {
141+ " type" : " none" ,
142+ " series" : []
143+ },
144+ " metric" : {
145+ " step" : 4 ,
146+ " property" : " price"
147+ }
148+ }
149+
150+
151+ Segmentation result
152+ -------------------
153+
154+ You can also export the result of a segmentation for a specific customer
155+ (whom you need to specify either at initialization, or using the `identify ` method).
156+ It is necessary to authenticate during initialization of the client (see above).
157+
158+ .. code-block :: python
159+
160+ client = Infinario(' 12345678-90ab-cdef-1234-567890abcdef' ,
161+ secret = ' fedcba09-8765-4321-fedc-ba0987654321' ,
162+ customer = ' john123' )
163+
164+ segment = client.segment_for(' 11112222-3333-4444-5555-666677778888' ,
165+ timezone = ' UTC' , timeout = 0.5 )
166+
167+ The result is the segmentation name, a string like `'Heavy payer' `. In case the customer doesn't belong to any
168+ defined segment or their segmentation could not be determined within the given timeout, the method will return `None `.
169+ The `timezone ` and `timeout ` parameters are optional with the defaults as in the example.
170+
171+
95172Transport types
96173---------------
97174
98175By default the client uses a simple non-buffered synchronous transport. The three available transport types are:
99176* `NullTransport ` - No requests, useful for disabling tracking in the Infinario constructor.
100- * `SynchronousTransport ` - Most operations are blocking for the time of a request to the Infinario API
177+ * `SynchronousTransport ` - (default) Most operations are blocking for the time of a request to the Infinario API
101178* `AsynchronousTransport ` - Most operations are non-blocking (see the code for more information),
102179 buffered and using a single worker thread. Infinario client must be closed when no more data is to be tracked.
180+ **We recommend against using the AsynchronousTransport, as it cannot be guaranteed the data will be sent. **
181+ Data loss can for example happen in various events of system failure or even due to misuse.
182+ If you would like to track data from your code asynchronously, consider creating your own asynchronous workers
183+ using a library such as celery and use the SynchronousTransport to send the data from there.
103184
104- Example of choosing a transport :
185+ Example of choosing ` AsynchronousTransport ` :
105186
106187.. code-block :: python
107188
@@ -114,6 +195,7 @@ Example of choosing a transport:
114195
115196 client.close()
116197
198+
117199 Using on the command line
118200-------------------------
119201
@@ -132,52 +214,3 @@ The python client also has a command-line interface that allows to call its esse
132214
133215 # Get HTML from campaign
134216 ./infinario.py get_html " $TOKEN " " $CUSTOMER " " Banner left"
135-
136- Infinario Python Authenticated API client
137- =========================================
138-
139- The `infinario.AuthenticatedInfinario ` class provides access to the Infinario
140- synchronous Python authenticated API. In order to export analyses you have to instantiate client
141- with username and password of user that has ExtAPI access:
142-
143- .. code-block :: python
144-
145- from infinario import AuthenticatedInfinario
146-
147- client = AuthenticatedInfinario(' username' , ' password' )
148-
149- Exporting analyses
150- ------------------
151-
152- First argument is type of analysis (funnel, report, retention, segmentation),
153- second argument is JSON. In case that authenticated customer has access to multiple companies use keyword argument
154- `token=token_of_company_with_given_analysis `
155-
156- .. code-block :: python
157-
158- client.export_analysis(' funnel' , {
159- ' analysis_id' : ' 2f86608f-24f5-11e3-9950-c48508494cf5'
160- })
161-
162- will return
163-
164- .. code-block :: python
165-
166- {
167- " success" : true,
168- " name" : " Conversion funnel" ,
169- " steps" : [" First visit" , " Registration" , " First log in" , " Purchase" , " Payment" ],
170- " total" : {
171- " counts" : [48632 , 24120 , 20398 , 1256 , 1250 ],
172- " times" : [- 1 , 680 , 4502 , 45 , 540 , 300 ],
173- " metric" : 1987562
174- },
175- " drill_down" : {
176- " type" : " none" ,
177- " series" : []
178- },
179- " metric" : {
180- " step" : 4 ,
181- " property" : " price"
182- }
183- }
0 commit comments