-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpiwikAnalyticsAPI.livecode
More file actions
5594 lines (4567 loc) · 219 KB
/
piwikAnalyticsAPI.livecode
File metadata and controls
5594 lines (4567 loc) · 219 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
script "piwikAnalyticsAPI"
local sAnalytics
local sUserParameters
local sBulk, sBulkRequestsCount
-----------------------------------------------------------------------------------------------------
-- initAnalytics
--DESCRIPTION:
-- This command takes all what we need for tracking
--PARAMETERS:
-- none
--CHANGES:
-- 6/2/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command initAnalytics
-- URL for tracking with Piwik, see the example below
put "http://demo.piwik.org/piwik.php?" into tAnalytics["track_url"]
-- URL for getting data from Piwik(Report), see the example below
put "http://demo.piwik.org/index.php?" into tAnalytics["report_url"]
-- Your Piwik Server token which you can find in settings (Peronal Settings>API)
put "YOUR PIWIK SERVER TOKEN" into tAnalytics["token"]
-- Piwik website URL which you want to track or to get reports about
-- eg. &url=http://test.website.com
put "&url=PIWIK WEB SITE URL" into tAnalytics["app_url"]
-- Put the ID of site which you want to track or to get reports about
--.eg &idsite=21&rec=1 (rec is always 1, it is required parameter)
put "&idsite=ID OF WEBSITE&rec=1" into tAnalytics["app_siteid"]
put tAnalytics into sAnalytics
end initAnalytics
-----------------------------------------------------------------------------------------------------
-- setUserInfo
--DESCRIPTION:
-- This command sets Piwik user information
--PARAMETERS:
-- pUserInfo: Is array with user information parameters (Recommended parameters)
-- pUserInfo["_id"]: The unique visitor ID, must be a 16 characters hexadecimal string. Every unique visitor
-- must be assigned a different ID and this ID must not change after it is assigned.
-- pUserInfo["lang"]: This value is used to detect the visitor's country.
-- pUserInfo["uid"]: defines the User ID for this request. User ID is any non empty unique string identifying
-- the user (such as an email address or a username). To access this value, users must be
-- logged-in in your system so you can fetch this user ID from your system, and pass it to Piwik.
-- pUserInfo["res"]: The resolution of the device the visitor is using, eg 1280x1024.
-- pUserInfo["_cvar"]: Visit scope custom variables. This is a JSON encoded string of the custom variable array
-- Like: { "1": [ "OS", "iphone 5.0" ], "2": [ "Piwik Mobile Version", "1.6.2" ] }
--CHANGES:
-- 6/2/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command setUserInfo pUserInfo
-- Build user info parameters to POST to server
repeat for each key tInfo in pUserInfo
put "&" & tInfo & "=" & pUserInfo[tInfo] after tUserParameters
end repeat
-- Save info for using within every request
put tUserParameters into sUserParameters
end setUserInfo
-----------------------------------------------------------------------------------------------------
-- trackPage
--DESCRIPTION:
-- This command add view for page(track the page by pagename)
--PARAMETERS:
-- pPageName: Name of page which we want to track
--CHANGES:
-- 6/2/2016: Narek - Created the fuction
-----------------------------------------------------------------------------------------------------
command trackPage pPageName
-- Checking required parameters
if pPageName is empty then
answer "For page tracking PageName is required"
exit trackPage
end if
-- In url we can't have white spaces
replace space with "_" in pPageName
-- Put page name and page path in url
put sAnalytics["app_url"] & "window/" after tTrackURL
put pPageName after tTrackURL
if pPageName contains "/" then
set the itemDel to "/"
put the last item of pPageName into pPageName
end if
put "&action_name=" & pPageName after tTrackURL
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackPage
-----------------------------------------------------------------------------------------------------
-- trackEvent
--DESCRIPTION:
-- This command track actions within the page
--PARAMETERS:
-- pEventAction: The event action. Must not be empty. (eg. Play, Pause, Duration, Add Playlist,)
-- pEventCategory: The event category. Must not be empty. (eg. Videos, Music, Games...)
-- pEventName: The event name. (eg. a Movie name, or Song name)
--CHANGES:
-- 6/8/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackEvent pEventAction pEventCategory pEventName
-- Checking required parameters
if pEventAction is empty then
answer "For page tracking EventAction is required"
exit trackEvent
end if
if pEventCategory is empty then
answer "For page tracking EventCategory is required"
exit trackEvent
end if
-- Put action name and path into url
put sAnalytics["app_url"] & "events/" after tTrackURL
put pEventAction after tTrackURL
-- Builds Events tracking parameters
put "&e_c=" & pEventCategory after tTrackURL
put "&e_a=" & pEventAction after tTrackURL
if pEventName is not empty then
put "&e_n=" & pEventName after tTrackURL
end if
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackEvent
-----------------------------------------------------------------------------------------------------
-- trackException
--DESCRIPTION:
-- This command track exeptions
--PARAMETERS:
-- pExaptionName: Name of exception which user wants to track
--CHANGES:
-- 6/8/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackException pExceptionName
-- Checking required parameters
if pExceptionName is empty then
answer "For page tracking ExceptionName is required"
exit trackException
end if
-- Put exception name and path into url
put sAnalytics["app_url"] & "exception/" after tTrackURL
put pExceptionName after tTrackURL
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackException
-----------------------------------------------------------------------------------------------------
-- trackSearch
--DESCRIPTION:
-- This command track exeptions
--PARAMETERS:
-- pSearchKeyword: What user search in app
-- pSearchCat: Category of search keyword
-- pResultCount: Searsh results count.. in order we can know if user finds what he searched
--CHANGES:
-- 6/8/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackSearch pSearchKeyword, pSearchCat, pResultCount
-- Checking required parameters
if pSearchKeyword is empty then
answer "For page tracking Search Keyword is required"
exit trackSearch
end if
-- Put exception name and path into url
put sAnalytics["app_url"] & "search/" after tTrackURL
-- Put parameters into url for tracking search keywords, category and result count
put "&search=" & pSearchKeyword after tTrackURL
if pSearchCat is not empty then
put "&search_cat=" & pSearchCat after tTrackURL
end if
if pResultCount is not empty then
put "&search_count=" & pResultCount after tTrackURL
else
-- When keywords are tracked with "&search_count=0"
-- they will appear in the "No Result Search Keyword" report.
put "&search_count=0" after tTrackURL
end if
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackSearch
-----------------------------------------------------------------------------------------------------
-- trackGoal
--DESCRIPTION:
-- This command is tracking request will trigger a conversion for the goal of the app
--PARAMETERS:
-- pGoalID: ID of goal which wi can get from server
-- pRevenue: A monetary value that was generated as revenue by this goal conversion
--CHANGES:
-- 6/8/2016: Narek - Created the command
----------------------------------------------------------------------------------------------------
command trackGoal pGoalID pRevenue
-- Checking required parameters
if pGoalID is empty then
answer "For page tracking goal ID is required"
exit trackGoal
end if
-- Put path of app into url
put sAnalytics["app_url"] after tTrackURL
-- Put Goal id into URL
put "&idgoal=" & pGoalID after tTrackURL
if pRevenue is not empty then
put "&revenue=" & pRevenue after tTrackURL
end if
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackGoal
-----------------------------------------------------------------------------------------------------
-- trackEcommerceOrder
--DESCRIPTION:
-- Tracks an Ecommerce order, including any ecommerce item previously added to the order.
--PARAMETERS:
-- pOrderID: The unique string identifier for the ecommerce order: (required)
-- pGrandTotal: The grand total for the ecommerce order: (required)
-- pSubTotal: The sub total of the order; excludes shipping
-- pTax: Tax Amount of the order
-- pShipping: Shipping cost of the Order
-- pDiscount: Discount offered
--CHANGES:
-- 6/10/2016: Narek - Created the command
----------------------------------------------------------------------------------------------------
command trackEcommerceOrder pOrderID, pGrandTotal, pSubTotal, pTax, pShipping, pDiscount
-- Checking required parameters
if pOrderID is empty then
answer "For page tracking Order ID is required"
exit trackEcommerceOrder
end if
if pGrandTotal is empty then
answer "For page tracking Grand Total is required"
exit trackEcommerceOrder
end if
-- Put path of app into url
put sAnalytics["app_url"] after tTrackURL
-- Put order ID and revenue into url parameters
put "&ec_id=" & pOrderID after TrackURL
put "&revenue =" & pGrandTotal after TrackURL
-- You must set &idgoal=0 in the request to track an ecommerce interaction
put "&idgoal=0" after TrackURL
--------Checking the parameters and put them into post url----------
if pSubTotal is not empty then
put "&ec_st=" & pSubTotal after tTrackURL
end if
if pTax is not empty then
put "&ec_tx=" & pTax after tTrackURL
end if
if pShipping is not empty then
put "&ec_sh=" & pShipping after tTrackURL
end if
if pDiscount is not empty then
put "&ec_dt=" & pDiscount after tTrackURL
end if
----------------------------------------------------------------------------
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackEcommerceOrder
-----------------------------------------------------------------------------------------------------
-- trackEcommerceCartUpdate
--DESCRIPTION:
-- Tracks a shopping cart. Call this every time a user is
-- adding, updating or deleting a product from the cart.
--PARAMETERS:
-- pGrantTotal: Cart grand total (typically the sum of all items prices)
--CHANGES:
-- 6/18/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackEcommerceCartUpdate pGrantTotal
-- Checking required parameters
if pGrantTotal is empty then
answer "For page tracking Grant total is required"
exit trackEcommerceCartUpdate
end if
-- Put path of app into url
put sAnalytics["app_url"] after tTrackURL
-- Put grant total into url parameters
put "&revenue =" & pGrandTotal after TrackURL
-- You must set &idgoal=0 in the request to track an ecommerce interaction
put "&idgoal=0" after TrackURL
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackEcommerceCartUpdate
-----------------------------------------------------------------------------------------------------
-- checkConnectionStatus
--DESCRIPTION:
-- This function checks the connection, if no connection we can't track app
--PARAMETERS:
-- none:
--CHANGES:
-- 6/18/2016: Narek - Created the fuction
----------------------------------------------------------------------------------------------------
private function checkConnectionStatus
try
-- If the response of URL is not empty it means connection is correct
put ("http://www.google.com") into tCheckURL
put URL(tCheckURL) into tConnCheck
catch tError
end try
if tConnCheck is empty then
return false
else
return true
end if
end checkConnectionStatus
-----------------------------------------------------------------------------------------------------
-- bulkTracking
--DESCRIPTION:
-- Build the bulk Json of all request end send it to server for tracking. Returns result of tracking
--PARAMETERS:
-- none:
--CHANGES:
-- 6/18/2016: Narek - Created the fuction
----------------------------------------------------------------------------------------------------
private function bulkTracking
-- Put token into bulk array
put sAnalytics["token"] into sBulk["token_auth"]
-- Convert it to Json for sending
put ArrayToJSON(sBulk) into tBulkJson
-- Sending json
post tBulkJson to URL(sAnalytics["track_url"])
-- Getting the result
return it
end bulkTracking
-----------------------------------------------------------------------------------------------------
-- trackContentImpression
--DESCRIPTION:
-- Tracks a content impression using the specified values.
--PARAMETERS:
-- pContentName: The name of the content. For instance 'Ad Foo Bar'
-- pContentPiece: The actual content piece. For instance the path to an image, video, audio, any text
-- pContentTarget: The target of the content. For instance the URL of a landing page
--CHANGES:
-- 6/10/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackContentImpression pContentName, pContentPiece, pContentTarget
-- Checking required parameters
if pContentName is empty then
exit trackContentImpression
end if
-- Put action name and path into url
put sAnalytics["app_url"] & "conent/" after tTrackURL
put pContentName after tTrackURL
-- Builds Events tracking parameters
put "&c_n=" & pContentName after tTrackURL
if pContentPiece is not empty then
put "&c_p=" & pContentPiece after tTrackURL
end if
if pContentTarget is not empty then
put "&c_t=" & pContentTarget after tTrackURL
end if
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackContentImpression
-----------------------------------------------------------------------------------------------------
-- trackContentInteraction
--DESCRIPTION:
-- Tracks a content interaction using the specified values.
--PARAMETERS:
-- pContentInteraction: The name of the interaction with the content. For instance a 'click'
-- pContentName: The name of the content. For instance 'Ad Foo Bar'
-- pContentPiece: The actual content piece. For instance the path to an image, video, audio, any text
-- pContentTarget: The target of the content. For instance the URL of a landing page
--CHANGES:
-- 6/10/2016: Narek - Created the command
-----------------------------------------------------------------------------------------------------
command trackContentInteraction pContentInteraction, pContentName, pContentPiece, pContentTarget
-- Checking required parameters
if pContentInteraction is empty then
exit trackContentInteraction
end if
if pContentName is empty then
exit trackContentInteraction
end if
-- Put action name and path into url
put sAnalytics["app_url"] & "conent/" after tTrackURL
put pContentName after tTrackURL
-- Builds Events tracking parameters
put "&c_i=" & pContentInteraction after tTrackURL
put "&c_n=" & pContentName after tTrackURL
if pContentPiece is not empty then
put "&c_p=" & pContentPiece after tTrackURL
end if
if pContentTarget is not empty then
put "&c_t=" & pContentTarget after tTrackURL
end if
-- ID of our app server
put sAnalytics["app_siteid"] after tTrackURL
------------------------------------------------------------------
-- Checking the connection
------------------------------------------------------------------
if checkConnectionStatus() is false then
--------------------------------------------------------------------------------------
-- If no internet connection then keep requests in bulk to send after
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
-- Formating the parameters
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
else
--------------------------------------------------------------------------------------
-- We have connection, so we need to check if we have requests to send
--------------------------------------------------------------------------------------
-- No Data in bulk to send
if sBulk is empty then
-- Send data
get url (sAnalytics["track_url"] & "?token_auth=" & sAnalytics["Token"] & tTrackURL & sUserParameters)
else
--------------------------------------------------------------------------------------
-- Put the current request into requests bulk and send to server
--------------------------------------------------------------------------------------
add 1 to sBulkRequestsCount
put "?" into char 1 of tTrackURL
put tTrackURL & sUserParameters into sBulk["requests"][sBulkRequestsCount]
-- Send requests bulk
put bulkTracking() into tResult
-- Check the result
if tResult contains "success" then
put empty into sBulk
put 0 into sBulkRequestsCount
end if
--------------------------------------------------------------------------------------
end if
end if
end trackContentInteraction
---------------------------------------------------------------------------------------------------------------------
-- actionsGet
--DESCRIPTION:
-- Fuction returns all action information: (pageviews, unique pageviews, downloads, unique downloads
-- outlinks, unique outlinks, searches, keywords, avg. time generation)
--PARAMETERS:
-- pSiteID: ID of site which information we want to get
-- pPeriod: The period you request the statistics for. Can be any of: day, week, month, year or range.
-- For example to request a report for the range Jan 1st to Feb 15th you would write
-- &period=range&date=2011-01-01,2011-02-15
-- pDate: standard format = YYYY-MM-DD;
-- magic keywords = today or yesterday;
-- Range of dates:
-- lastX = for exaple "&date=last10" returns last 10 periods including today
-- previousX = for exaple "&date=previous10" returns the last 10 periods before today
-- pSegment: defines the Custom Segment you wish to filter your reports to for example,
-- 'referrerName==twitter.com' will return the requested API report,
-- processed for the subset of users coming from twitter.com
-- Segment Documenation: http://developer.piwik.org/api-reference/reporting-api-segmentation
-- pOtherParameters: Array with other, not required parameters for getting the reports.
-- pOtherParameters["PARAMETER NAME"] = VALUE
--CHANGES:
-- 6/22/2016: Narek - Created the fuction
---------------------------------------------------------------------------------------------------------------------
function actionsGet pSiteID, pPeriod, pDate, pSegment, pOtherParameters
-- Checking the required parameters
if pSiteID is empty then
return "Error: pSiteID is required"
end if
if pPeriod is empty then
return "Error: pPeriod is required"
end if
if pDate is empty then
return "Error: pDate is required"
end if
-- Disable the SSL verification
libURLSetSSLVerification false
-- Setting the headers
put "Content-Type: application/json" & cr after tHeader
set the httpheaders to tHeader
-- Default parameters for current report
put "?module=API&method=Actions.get" into tAPICall
put "&format=Json" after tAPICall
-- Build api call with passed required parameters
put "&idSite=" & pSiteID after tAPICall
put "&period=" & pPeriod after tAPICall
put "&date=" & pDate after tAPICall
-- Build segment parameter
if pSegment is not empty then
put "&segment=" & pSegment after tAPICall
end if
-- Build other, not required paramters for request
if pOtherParameters is not empty then
repeat for each key tParam in pOtherParameters
put "&" & tParam & "=" & pOtherParameters[tParam] after tAPICall
end repeat
end if
-- Do GET request method for getting the data
GET URL(sAnalytics["report_url"] & tAPICall & "&token_auth=" & sAnalytics["token"])
put it into tResult
-- Convert the json to Livecode array
put JSONToArray(tResult) into tResultArray
-- Getting the report
return tResultArray
end actionsGet
---------------------------------------------------------------------------------------------------------------------
-- actionsGetPageURLsList
--DESCRIPTION:
-- This function returns all pages urls witihin the current website
--PARAMETERS:
-- pSiteID: ID of site which information we want to get
-- pPeriod: The period you request the statistics for. Can be any of: day, week, month, year or range.
-- For example to request a report for the range Jan 1st to Feb 15th you would write
-- &period=range&date=2011-01-01,2011-02-15
-- pDate: standard format = YYYY-MM-DD;
-- magic keywords = today or yesterday;
-- Range of dates:
-- lastX = for exaple "&date=last10" returns last 10 periods including today
-- previousX = for exaple "&date=previous10" returns the last 10 periods before today
-- pSegment: defines the Custom Segment you wish to filter your reports to for example,
-- 'referrerName==twitter.com' will return the requested API report,
-- processed for the subset of users coming from twitter.com
-- Segment Documenation: http://developer.piwik.org/api-reference/reporting-api-segmentation
-- pOtherParameters: Array with other, not required parameters for getting the reports.
-- pOtherParameters["PARAMETER NAME"] = VALUE
--CHANGES:
-- 6/22/2016: Narek - Created the fuction
---------------------------------------------------------------------------------------------------------------------
function actionsGetPageURLsList pSiteID, pPeriod, pDate, pSegment, pOtherParameters
-- Checking the required parameters
if pSiteID is empty then
return "Error: pSiteID is required"
end if
if pPeriod is empty then
return "Error: pPeriod is required"
end if
if pDate is empty then
return "Error: pDate is required"
end if
-- Disable the SSL verification
libURLSetSSLVerification false
-- Setting the headers
put "Content-Type: application/json" & cr after tHeader
set the httpheaders to tHeader
-- Default parameters for current report
put "?module=API&method=Actions.getPageUrls" into tAPICall
put "&format=Json" after tAPICall
-- Build api call with passed required parameters
put "&idSite=" & pSiteID after tAPICall
put "&period=" & pPeriod after tAPICall
put "&date=" & pDate after tAPICall
-- Build segment parameter
if pSegment is not empty then
put "&segment=" & pSegment after tAPICall
end if
-- Build other, not required paramters for request
if pOtherParameters is not empty then
repeat for each key tParam in pOtherParameters
put "&" & tParam & "=" & pOtherParameters[tParam] after tAPICall
end repeat
end if
-- Do GET request method for getting the data
GET URL(sAnalytics["report_url"] & tAPICall & "&token_auth=" & sAnalytics["token"])
put it into tResult
-- Convert the json to Livecode array
put JSONToArray(tResult) into tResultArray