简体   繁体   中英

Use web sdk plugin in ionic 4 application

I have one question. I want to use this sdk in my ionic application : https://support.count.ly/hc/en-us/articles/360037441932-Web-analytics-JavaScript-#using-the-web-sdk-in-webview . I use the ionic version 4 so I can't use their plugin because is compatible only with ionic 2. The question is how I can use this plugin inside my component ? What I did till now :

1. npm install countly-sdk-web
2. I modified index.html file to add the init :
<script type='text/javascript'>

// Some default pre init
var Countly = Countly || {};
Countly.q = Countly.q || [];

// Provide your app key that you retrieved from Countly dashboard
Countly.app_key = "111";

// Provide your server IP or name. Use try.count.ly or us-try.count.ly
// or asia-try.count.ly for EE trial server.
// If you use your own server, make sure you have https enabled if you use
// https below.
Countly.url = "https://try.count.ly";

// Start pushing function calls to queue
// Track sessions automatically (recommended)
Countly.q.push(['track_sessions']);

//track web page views automatically (recommended)
Countly.q.push(['track_pageview']);

// Load Countly script asynchronously
(function() {
  var cly = document.createElement('script'); cly.type = 'text/javascript';
  cly.async = true;
  // Enter url of script here (see below for other option)
  cly.src = 'https://cdn.jsdelivr.net/npm/countly-sdk-web@latest/lib/countly.min.js';
  cly.onload = function(){Countly.init()};
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
})();

No errors, so the sdk is initiated. But no idea how to use on .component.ts . Have some ideas ? Thx in advance

I'm one of the developers working at Countly.

Is there a reson you want to use the web SDK in your Ionic application? It's main usage is for web pages and not mobile applications.

For Ionic mobile (Android and iOS) applications we recommend our "Cordova SDK".

To get a better undestanding how to use our SDK in your application, please check our documentation and example app .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM