0.2.1 • Published 3 months ago

@snowplow/webview-tracker v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

Snowplow WebView Tracker

early-release Build Status Release License

Snowplow is a scalable open-source platform for rich, high quality, low-latency data collection. It is designed to collect high quality, complete behavioral data for enterprise business.

To find out more, please check out the Snowplow website and our documentation.

Snowplow WebView Tracker Overview

The Snowplow WebView Tracker allows you to add analytics to your Web views embedded in mobile apps when using a Snowplow pipeline.

The WebView tracker should be integrated in Web apps used in Web views within native mobile apps. The tracker provides APIs to track Snowplow events. It forwards the events to the native app code to be tracked by the Snowplow mobile trackers (iOS, Android tracker, or React Native). The diagram below shows the interaction of the WebView and mobile trackers in hybrid apps.

flowchart TB

subgraph hybridApp[Hybrid Mobile App]

    subgraph webView[Web View]
        webViewCode[App logic]
        webViewTracker[Snowplow WebView tracker]

        webViewCode -- "Tracks events" --> webViewTracker
    end

    subgraph nativeCode[Native Code]
        nativeAppCode[App logic]
        nativeTracker[Snowplow iOS/Android/React Native tracker]

        nativeAppCode -- "Tracks events" --> nativeTracker
    end

    webViewTracker -- "Forwards events" --> nativeTracker
end

subgraph cloud[Cloud]
    collector[Snowplow Collector]
end

nativeTracker -- "Sends tracked events" --> collector

Technical documentation can be found for each tracker in our Hybrid Apps accelerator.

Quick Start

Installation from npm

To install the WebView tracker in your JavaScript or TypeScript app, add the npm package:

npm install --save @snowplow/webview-tracker

You will then be able to use the functions provided by the WebView tracker as follows:

import { trackSelfDescribingEvent } from '@snowplow/webview-tracker';

In addition, you will need to install the iOS or Android tracker in your native code and configure and initialize a tracker (see the mobile tracker docs). Afterwards, you will be able to subscribe to and track the events from the WebView tracker in a Web view by calling Snowplow.subscribeToWebViewEvents(webView).

Installation with the Snowplow tag

You may download the sp.js file from the Releases section Github, self-host it, and load to your page using the following tag:

<script type="text/javascript" async=1>
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","{{URL to sp.js}}","snowplow"));
</script>

Using the Tracker

To track events, simply call their corresponding functions given the event data:

trackSelfDescribingEvent({
    event: {
        schema: 'iglu:com.example_company/save_game/jsonschema/1-0-2',
        data: {
            'saveId': '4321',
            'level': 23,
            'difficultyLevel': 'HARD',
            'dlContent': true
        }
    }
});

In case you loaded the tracker using the Snowplow tag, you will be able to access the APIs using window.snowplow:

window.snowplow('trackSelfDescribingEvent', {
    event: {
        schema: 'iglu:com.example_company/save_game/jsonschema/1-0-2',
        data: {
            'saveId': '4321',
            'level': 23,
            'difficultyLevel': 'HARD',
            'dlContent': true
        }
    }
});

Please refer to the tracker documentation to learn more about the APIs.

Find Out More

Technical Docs
i1
Technical Docs

Maintainers

Contributing
i4
Contributing

Copyright and License

The Snowplow WebView Tracker is copyright 2022 Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

0.2.1

3 months ago

0.2.0

2 years ago

0.1.0

2 years ago

0.1.0-dev.1

2 years ago