Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for Flutter Web on Flutter 4.0 #456

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ updated_by: 0c3a318b-936a-4cbd-8fdf-771a90c297f0
updated_at: 1718672484
source: 'https://www.docs.developers.amplitude.com/data/sdks/flutter/migration/'
---
Amplitude Flutter SDK 4.0 features default event tracking, simplified interfaces, and wraps the latest [Amplitude iOS](/docs/sdks/analytics/ios/ios-swift-sdk) and [Android Kotlin](/docs/sdks/analytics/android/android-kotlin-sdk) SDKs.
Amplitude Flutter SDK 4.0 features default event tracking, simplified interfaces, and wraps the latest [Amplitude iOS](/docs/sdks/analytics/ios/ios-swift-sdk), [Android Kotlin](/docs/sdks/analytics/android/android-kotlin-sdk), and [Browser Typescript](/docs/sdks/analytics/browser/browser-sdk-2) SDKs.


## Terminology
Expand Down Expand Up @@ -40,6 +40,27 @@ Open `Podfile` and update:

Run `pod install` under the ios directory of your Flutter project to update the CocoaPods dependencies.

For Flutter Web, replace the Amplitude-JavaScript snippet located at `web/index.html` with the following Browser SDK 2 snippet:
chungdaniel marked this conversation as resolved.
Show resolved Hide resolved
```html
<script type="text/javascript">
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}}
;if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.")
;else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}}
,s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}}
,o=function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})}
,i=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};o(e,t,Array.prototype.slice.call(arguments))}}
,a=function(e){for(var t=0;t<g.length;t++)i(e,g[t],!1);for(var r=0;r<m.length;r++)i(e,m[r],!0)}
;r.invoked=!0;var c=t.createElement("script")
;c.type="text/javascript",c.integrity="sha384-R0H1kXlk6r2aEQMtwVcPolpk0NAuIqM/8NlxAv24Gr3/PBJPl+9elu0bc3o/FDjR",c.crossOrigin="anonymous",c.async=!0
,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.11.10-min.js.gz"
,c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")}
;var l=t.getElementsByTagName("script")[0];l.parentNode.insertBefore(c,l);for(var u=function(){return this._q=[],this}
,p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<p.length;d++)n(u,p[d]);r.Identify=u
;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<v.length;y++)n(f,v[y]);r.Revenue=f;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"]
;a(r),r.createInstance=function(e){return r._iq[e]={_q:[]},a(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
</script>
```

## Instrumentation

Flutter SDK 4.0 offers an API to instrument events. To migrate to Flutter SDK 4.0, you need to update a few calls. The following sections detail which calls have changed.
Expand Down Expand Up @@ -156,7 +177,7 @@ The APIs for setting user properties are the same, except for the removal of `in

### clearUserProperties()

The `clearUserProperties` API has been removed, but you can now use the unified `identify` API to remove user properties.
The `clearUserProperties` API has been removed, but you can now use the unified `identify` API to remove user properties.

```dart
amplitude.clearUserProperties(); //[tl! --]
Expand All @@ -167,7 +188,7 @@ amplitude.identify(identify);

### setUserProperties()

The `setUserProperties` API has been removed, but you can now use the unified `identify` API to add user properties.
The `setUserProperties` API has been removed, but you can now use the unified `identify` API to add user properties.

```dart
- Map<String, dynamic> userProps = { //[tl! --:4]
Expand Down Expand Up @@ -236,4 +257,4 @@ final Revenue revenue = Revenue() //[tl! ++:4]
..quantity = 3
..productId = "com.company.productId";
amplitude.revenue(revenue);
```
```
Loading
Loading