File: examples/example_async.html

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   examples/example_async.html   Download  
File: examples/example_async.html
Role: Documentation
Content type: text/plain
Description: Documentation
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: Content filtering
Date: 1 month ago
Size: 2,564 bytes
 

Contents

Class file image Download
<html> <head> <!-- Page styling here --> <link rel='stylesheet' type='text/css' href='./style/style.css'> <!--Countly script--> <script type='text/javascript'> //some default pre init var Countly = Countly || {}; Countly.q = Countly.q || []; //provide countly initialization parameters Countly.app_key = "YOUR_APP_KEY"; Countly.url = "https://your.server.ly"; //your server goes here if (Countly.app_key === "YOUR_APP_KEY" || Countly.url === "https://your.server.ly") { console.warn("Please do not use default set of app key and server url") } Countly.debug = true; //start pushing function calls to queue //track sessions automatically Countly.q.push(['track_sessions']); //content filter example function filter(params) { var shouldContentBeShown = true; console.log("Content filter called with params:", params); // Add your content filtering logic here and determine whether to show content return shouldContentBeShown; } //enter content zone with filter Countly.q.push(['content.enterContentZone', filter]); //track sessions automatically 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 cly.src = '../lib/countly.js'; cly.onload = function () { Countly.init() }; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s); })(); //send event on button click function clickEvent() { Countly.q.push(['add_event', { key: "buttonClick", "segmentation": { "id": "id" } }]); } function uploadProfilePicture() { var fileInput = document.getElementById("profilePicInput"); var file = fileInput.files[0]; if (!file) { alert("Please select an image file."); return; } Countly.q.push(["uploadUserProfilePicture", file]); } </script> </head> <body> <!-- Header, banner etc. Top part of your site --> <div id="header"> <h1>Async Countly Implementation</h1> <img id="logo" src="./images/logo.png"> </div> <center> <img src="./images/team_countly.jpg" id="wallpaper" /> <br /> <input type="button" id="testButton" onclick="clickEvent()" value="Test Button"> <br /><br /> <input type="file" id="profilePicInput" accept="image/*"> <br /><br /> <br /> <input type="button" onclick="uploadProfilePicture()" value="Upload Profile Picture"> <p><a href='https://countly.com/'>Countly</a></p> </center> </body> </html>