Skip to content

Commit

Permalink
Fix web example and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Jun 25, 2021
1 parent 164f635 commit f0be462
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 41 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,17 @@ Remember that the application lifecycle events won't have any special context se
```html
<!DOCTYPE html>
<html>
<head>
[...]
</head>
<body>
<script>
!function(){ ...;
posthog.init("YOUR_API_KEY_GOES_HERE", {api_host: 'https://app.posthog.com'});
posthog.page();
}}();
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init("YOUR_WRITE_KEY_GOES_HERE", {api_host: 'https://app.posthog.com'});
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
```

Expand Down
11 changes: 0 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ class MyApp extends StatelessWidget {
),
),
Spacer(),
Platform.isIOS
? Center(
child: TextButton(
child: Text('Debug mode'),
onPressed: () {
Posthog().debug(true);
},
),
)
: Container(),
Spacer(),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish_to: "none"
version: 0.0.1+1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand All @@ -15,7 +15,7 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.3

dev_dependencies:
flutter_test:
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text && widget.data.startsWith('Running on:'),
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
Binary file added example/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 5 additions & 13 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>example</title>
</head>

<body>
<script>
!function () {
var analytics = window.analytics = window.analytics || []; if (!analytics.initialize) if (analytics.invoked) window.console && console.error && console.error("Posthog snippet included twice."); else {
analytics.invoked = !0; analytics.methods = ["captureSubmit", "captureClick", "captureLink", "captureForm", "pageview", "identify", "reset", "group", "capture", "ready", "alias", "debug", "page", "once", "off", "on"]; analytics.factory = function (t) { return function () { var e = Array.prototype.slice.call(arguments); e.unshift(t); analytics.push(e); return analytics } }; for (var t = 0; t < analytics.methods.length; t++) { var e = analytics.methods[t]; analytics[e] = analytics.factory(e) } analytics.load = function (t, e) { var n = document.createElement("script"); n.type = "text/javascript"; n.async = !0; n.src = "https://cdn.posthog.com/analytics.js/v1/" + t + "/analytics.min.js"; var a = document.getElementsByTagName("script")[0]; a.parentNode.insertBefore(n, a); analytics._loadOptions = e }; analytics.SNIPPET_VERSION = "4.1.0";
analytics.load("YOUR_API_KEY_GOES_HERE");
analytics.page();
}
}();
</script>
<script src="main.dart.js" type="application/javascript"></script>
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init("YOUR_WRITE_KEY_GOES_HERE", {api_host: 'https://app.posthog.com'});
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>

</html>
23 changes: 23 additions & 0 deletions example/web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "myapp",
"short_name": "myapp",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
6 changes: 4 additions & 2 deletions lib/src/posthog_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import 'dart:js';
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart' show Registrar;


class PosthogWeb {
static void registerWith(Registrar registrar) {
final MethodChannel channel = MethodChannel(
'posthog_flutter',
'posthogflutter',
const StandardMethodCodec(),
registrar.messenger,
);
final PosthogWeb instance = PosthogWeb();
channel.setMethodCallHandler(instance.handleMethodCall);
Expand All @@ -29,7 +31,7 @@ class PosthogWeb {
]);
break;
case 'screen':
analytics.callMethod('page', [
analytics.callMethod('capture', [
call.arguments['screenName'],
JsObject.jsify(call.arguments['properties']),
]);
Expand Down

0 comments on commit f0be462

Please sign in to comment.