From cc8a0a14a873c12f088e38e92d7f6ccc80e22108 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Wed, 28 Jul 2021 11:07:42 +0200 Subject: [PATCH 1/4] adding dune dependencie into opam --- mixpanel.opam | 1 + 1 file changed, 1 insertion(+) diff --git a/mixpanel.opam b/mixpanel.opam index 64547a4..6946db2 100644 --- a/mixpanel.opam +++ b/mixpanel.opam @@ -11,6 +11,7 @@ synopsis: "Binding to the mixpanel plugin using gen_js_api" build: [[ "dune" "build" "-j" jobs "-p" name "@install" ]] depends: [ "ocaml" { >= "4.08.0" } + "dune" {>= "2.7"} "gen_js_api" "js_of_ocaml" "js_of_ocaml-ppx" From 23de00601e6c5d674c60babb5714936479d26514 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Fri, 10 Sep 2021 17:21:46 +0200 Subject: [PATCH 2/4] adding the 'script' function into the 3.2 version --- mixpanel.opam | 3 ++- src/base.mli | 32 ++++++++++++++++++++++++++++++++ src/dune | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/mixpanel.opam b/mixpanel.opam index 6946db2..d486da8 100644 --- a/mixpanel.opam +++ b/mixpanel.opam @@ -1,5 +1,5 @@ opam-version: "2.0" -version: "3.1.1" +version: "3.2" maintainer: "Thibaut Gudin " authors: "Thibaut Gudin " homepage: "https://github.com/besport/ocaml-mixpanel" @@ -16,4 +16,5 @@ depends: [ "js_of_ocaml" "js_of_ocaml-ppx" "lwt_ppx" + "tyxml" ] diff --git a/src/base.mli b/src/base.mli index 4ff1e6c..4650b4a 100644 --- a/src/base.mli +++ b/src/base.mli @@ -96,12 +96,44 @@ val reset : unit -> unit [@@js.global "mixpanel.reset"] val available : unit -> bool +val script : unit -> [> Html_types.script ] Tyxml_html.elt list + [@@@js.start] [@@@js.implem let available () = Js_of_ocaml.Js.Optdef.test Js_of_ocaml.Js.Unsafe.global##.mixpanel] +[@@@js.implem +let script () = + [ Tyxml.Html.script + (Tyxml.Html.cdata_script + "(function(c,a){if(!a.__SV){var b=window;try{var \ + d,m,j,k=b.location,f=k.hash;d=function(a,b){return(m=a.match(RegExp(b+'=([^&]*)')))?m[1]:null};f&&d(f,'state')&&(j=JSON.parse(decodeURIComponent(d(f,'state'))),'mpeditor'===j.action&&(b.sessionStorage.setItem('_mpcehash',f),history.replaceState(j.desiredHash||'',c.title,k.pathname+k.search)))}catch(n){}var \ + l,h;window.mixpanel=a;a._i=[];a.init=function(b,d,g){function \ + c(b,i){var \ + a=i.split('.');2==a.length&&(b=b[a[0]],i=a[1]);b[i]=function(){b.push([i].concat(Array.prototype.slice.call(arguments,\n\ + 0)))}}var e=a;'undefined'!==typeof \ + g?e=a[g]=[]:g='mixpanel';e.people=e.people||[];e.toString=function(b){var \ + a='mixpanel';'mixpanel'!==g&&(a+='.'+g);b||(a+=' (stub)');return \ + a};e.people.toString=function(){return e.toString(1)+'.people \ + (stub)'};l='disable time_event track track_pageview track_links \ + track_forms track_with_groups add_group set_group remove_group \ + register register_once alias unregister identify name_tag set_config \ + reset opt_in_tracking opt_out_tracking has_opted_in_tracking \ + has_opted_out_tracking clear_opt_in_out_tracking people.set \ + people.set_once people.unset people.increment people.append \ + people.union people.track_charge people.clear_charges \ + people.delete_user people.remove'.split(' ');\n\ + for(h=0;h group_ids:string list -> diff --git a/src/dune b/src/dune index 45ef7d4..b7cf219 100644 --- a/src/dune +++ b/src/dune @@ -7,6 +7,6 @@ (public_name mixpanel) (name mixpanel) (modes byte) - (libraries gen_js_api js_of_ocaml js_of_ocaml-ppx lwt_ppx) + (libraries gen_js_api js_of_ocaml js_of_ocaml-ppx lwt_ppx tyxml) (preprocess (pps js_of_ocaml-ppx lwt_ppx)) ) From 5ed71a5ee9d455b60e2ff991d3bbaba9f9b4e089 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Fri, 10 Sep 2021 18:12:30 +0200 Subject: [PATCH 3/4] README updated --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 9e9a4ae..4712ebd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,19 @@ functions that depend on the server Mixpanel, if "available" retrun their will be a chance that program became stuck: waiting a reponse of Mixpanel that could never came). +### `Mixpanel.script` +This function execute a pre-defined *Java Script* script in your app, it +is recommended to call this function in server side of your app befor to +use other function if this script is suitable for you. You can see what +this script do in the `base.mli` file. +This script is retruned in the form of an `[> Html_types.script ] +Tyxml_html.elt list` value. It require you to use the `TyXML` librarie, +you can see the [Ocsigen official +documentation](https://ocsigen.org/tyxml/latest/manual/intro) for more +details, more precisely [this +section](https://ocsigen.org/tyxml/4.0/api/Html_sigs.Make.T) for a +better understanding of what this function return. + ### `Mixpanel.init` > This function initializes a new instance of the Mixpanel tracking object. All new instances are added to the main mixpanel object as sub From 4d750e66435a0c0ba0085b87c1ae98209da3c956 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Fri, 17 Sep 2021 14:50:55 +0200 Subject: [PATCH 4/4] other 3.2 implementation experimentation --- src/base.mli | 72 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/base.mli b/src/base.mli index 4650b4a..68f0526 100644 --- a/src/base.mli +++ b/src/base.mli @@ -96,7 +96,7 @@ val reset : unit -> unit [@@js.global "mixpanel.reset"] val available : unit -> bool -val script : unit -> [> Html_types.script ] Tyxml_html.elt list +val script : (unit -> unit) -> unit [@@@js.start] @@ -105,34 +105,48 @@ let available () = Js_of_ocaml.Js.Optdef.test Js_of_ocaml.Js.Unsafe.global##.mixpanel] [@@@js.implem -let script () = - [ Tyxml.Html.script - (Tyxml.Html.cdata_script - "(function(c,a){if(!a.__SV){var b=window;try{var \ - d,m,j,k=b.location,f=k.hash;d=function(a,b){return(m=a.match(RegExp(b+'=([^&]*)')))?m[1]:null};f&&d(f,'state')&&(j=JSON.parse(decodeURIComponent(d(f,'state'))),'mpeditor'===j.action&&(b.sessionStorage.setItem('_mpcehash',f),history.replaceState(j.desiredHash||'',c.title,k.pathname+k.search)))}catch(n){}var \ - l,h;window.mixpanel=a;a._i=[];a.init=function(b,d,g){function \ - c(b,i){var \ - a=i.split('.');2==a.length&&(b=b[a[0]],i=a[1]);b[i]=function(){b.push([i].concat(Array.prototype.slice.call(arguments,\n\ - 0)))}}var e=a;'undefined'!==typeof \ - g?e=a[g]=[]:g='mixpanel';e.people=e.people||[];e.toString=function(b){var \ - a='mixpanel';'mixpanel'!==g&&(a+='.'+g);b||(a+=' (stub)');return \ - a};e.people.toString=function(){return e.toString(1)+'.people \ - (stub)'};l='disable time_event track track_pageview track_links \ - track_forms track_with_groups add_group set_group remove_group \ - register register_once alias unregister identify name_tag set_config \ - reset opt_in_tracking opt_out_tracking has_opted_in_tracking \ - has_opted_out_tracking clear_opt_in_out_tracking people.set \ - people.set_once people.unset people.increment people.append \ - people.union people.track_charge people.clear_charges \ - people.delete_user people.remove'.split(' ');\n\ - for(h=0;h + Js.Opt.iter script##.parentNode (fun head -> + let js = Dom_html.createScript Dom_html.document in + js##.text := + Js.string + "(function(c,a){if(!a.__SV){var b=window;try{var \ + d,m,j,k=b.location,f=k.hash;d=function(a,b){return(m=a.match(RegExp(b+'=([^&]*)')))?m[1]:null};f&&d(f,'state')&&(j=JSON.parse(decodeURIComponent(d(f,'state'))),'mpeditor'===j.action&&(b.sessionStorage.setItem('_mpcehash',f),history.replaceState(j.desiredHash||'',c.title,k.pathname+k.search)))}catch(n){}var \ + l,h;window.mixpanel=a;a._i=[];a.init=function(b,d,g){function \ + c(b,i){var \ + a=i.split('.');2==a.length&&(b=b[a[0]],i=a[1]);b[i]=function(){b.push([i].concat(Array.prototype.slice.call(arguments,\n\ + 0)))}}var e=a;'undefined'!==typeof \ + g?e=a[g]=[]:g='mixpanel';e.people=e.people||[];e.toString=function(b){var \ + a='mixpanel';'mixpanel'!==g&&(a+='.'+g);b||(a+=' \ + (stub)');return a};e.people.toString=function(){return \ + e.toString(1)+'.people (stub)'};l='disable time_event track \ + track_pageview track_links track_forms track_with_groups \ + add_group set_group remove_group register register_once alias \ + unregister identify name_tag set_config reset opt_in_tracking \ + opt_out_tracking has_opted_in_tracking has_opted_out_tracking \ + clear_opt_in_out_tracking people.set people.set_once \ + people.unset people.increment people.append people.union \ + people.track_charge people.clear_charges people.delete_user \ + people.remove'.split(' ');\n\ + for(h=0;h