Code Monkey home page Code Monkey logo

amplitude-javascript's Introduction


Test npm version Bower version

Announcement ๐Ÿ“ฃ

Amplitude is introducing a new TypeScript SDK for Browser. This new SDK provides improved developer experience, helps users instrument data more seamlessly and provide more control over data being instrumented using custom plugins.

To learn more about the new SDK, here are some useful links:

Amplitude JS/Web SDK

A JavaScript SDK for tracking events and revenue to Amplitude.

Amplitude and Ampli SDK

Ampli SDK is autogenerated library based on your pre-defined tracking plan. The Ampli SDK, is a lightweight wrapper over the Amplitude SDK that provides type-safety, supports linting, and enables features like input validation. The code replicates the spec in the Tracking Plan and enforces its rules and requirements. This repository is about Amplitude SDK. To learn more about Ampli SDK, please refer to the Ampli Browser and examples.

Installation and Quick Start

Demo Pages

  • A demo page showing a simple integration on a web page.
  • A demo page showing an integration using RequireJS.
  • A demo page demonstrating a potential integration with Google Tag Manager.

Deprecated - React Native

As of >= v8.0.0, this SDK no longer has support for React Native. We recently released a new SDK focused on providing a React Native first approach to using Amplitude in cross-platform projects. Amplitude React Native SDK

Previously used amplitude-js and looking to migrate to @amplitude/react-native?

Node.js

Please visit Amplitude-Node for our Node SDK.

Changelog

Click here to view the JavaScript SDK Changelog.

Upgrading Major Versions and Breaking Changes

6.0

The cookie format has been changed to be more compact. If you use the same Amplitude project(API key) across multiple applications, and you track anonymous users across those applications, you will want to update amplitude across all those applications at the same time. Otherwise these anonymous users will have a different device id in your different applications.

If you do not have multiple installations of amplitude, or if you do not track anonymous users across different installations of amplitude, this change should not affect you.

5.0

We stopped committing the generated amplitude.min.js and amplitude.js files to the repository. This should only affect you if you load amplitude via github. You should use npm or yarn instead.

We dropped our custom symbian and blackberry user agent parsing to simply match what the ua-parser-js library does.

4.0

The library now defaults to sending requests to https://api.amplitude.com instead of //api.amplitude.com. This should only affect you if your site does not use https and you use a Content Security Policy.

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.

amplitude-javascript's People

Contributors

ajhorst avatar allanca avatar amplitude-sdk-bot avatar aoshika-lv avatar bgiori avatar blazzy avatar curtisliu avatar dependabot[bot] avatar djih avatar dnshi avatar falconandy avatar haoliu-amp avatar izaaz avatar jarrenpatao avatar jooohhn avatar justin-fiedler avatar kdastan avatar kelsonpw avatar kelvin-lu avatar kevinpagtakhan avatar liuyang1520 avatar mercy811 avatar qingzhuozhen avatar seanparmelee avatar semantic-release-bot avatar sputh avatar sskates avatar wilkerlucio avatar willheslam avatar yuhao900914 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amplitude-javascript's Issues

Cannot use with r.js compiler of requirejs AMD system

Hi there!

I cant compile in one file my amd modules (with you dependencies) because here https://github.com/amplitude/Amplitude-Javascript/blob/master/amplitude.js#L5 writen this code

return require('1')

can you change it on correct AMD wrapper
Smth like this

(function (root, factory) {
  if(typeof define === "function" && define.amd) {
    // Now we're wrapping the factory and assigning the return
    // value to the root (window) and returning it as well to
    // the AMD loader.
    define(["postal"], function(postal){
      return (root.myModule = factory(postal));
    });
  } else if(typeof module === "object" && module.exports) {
    // I've not encountered a need for this yet, since I haven't
    // run into a scenario where plain modules depend on CommonJS
    // *and* I happen to be loading in a CJS browser environment
    // but I'm including it for the sake of being thorough
    module.exports = (root.myModule = factory(require("postal")));
  } else {
    root.myModule = factory(root.postal);
  }
}(this, function(postal) {
  // module code here....
  return myModule;
}));

Thank you!

Internet Explorer 11 only issues with Amplitude (Error 504)

I have an issue using Amplitude that only appears to happen when using Internet Explorer 11 (Edge, Firefox, Chrome browsers all seem to work fine).

In the Network tab I can see the POST request to the Amplitude API returns a 504 GATEWAY_TIMEOUT error - the process takes around 65-70 seconds which causes the browser to hang/slowdown (see the image below).

amplitudejs

In the console.log I can see the following errors :-
SEC7120: Origin https://live.mywebsite.com not found in Access-Control-Allow-Origin header.
SCRIPT7002: XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.

Can anyone suggest how to fix this problem so it no longer causes the IE11 browser to hang?

I am using Amplitude version 2.9.0 (see snippet below)
<script type="text/javascript"> (function(e,t){var n=e.amplitude||{};var r=t.createElement("script");r.type="text/javascript"; r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.9.0-min.gz.js"; r.onload=function(){e.amplitude.runQueuedFunctions()};var s=t.getElementsByTagName("script")[0]; s.parentNode.insertBefore(r,s);var i=function(){this._q=[];return this};function a(e){ i.prototype[e]=function(){this._q.push([e].concat(Array.prototype.slice.call(arguments,0))); return this}}var o=["add","append","clearAll","set","setOnce","unset"];for(var c=0;c<o.length;c++){ a(o[c])}n.Identify=i;n._q=[];function u(e){n[e]=function(){n._q.push([e].concat(Array.prototype.slice.call(arguments,0))); }}var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties"]; for(var p=0;p<l.length;p++){u(l[p])}e.amplitude=n})(window,document); </script>

Using Amplitude with SSR (React)

Hi,

I am trying to migrate a codebase from client-side to server-side, and am using Amplitude like so:

import amplitude from 'amplitude-js/amplitude';

It is bundled by Webpack. On the server-side, I have this error:

document is not defined, l.3020, called by global scope block l.3007

I'm a bit lost on this, as there is browser-specific code in global scope and therefore it can't run on server...

Any insights?

Thanks in advance

Overriding Platform

Hi - is it possible to override the Platform variable?

We are using Amplitude with Cordova, and it always returns "Web" as opposed to the correct platform. We can set it manually, but just need to know if its possible

Amplitude v3.0.2 removed from repository

I liked that version very much so I kept it in my package.json for a long time, and now it is not there and all my CI jobs are angry shades of red and we are barricaded in our office behind some old Sun E450s while they try to knock it down to get to the version they want please help

Allow CORS to improve debugging

Hello,

Recently I am trying to debug error on our platform but none useful info is found from window.onerror handler, and I figure out it's because of same site origin policy.

And amplitude is the only 3rd party sdk our web app requires without correspondent Header:

curl -I https://cdn.amplitude.com/libs/amplitude-4.0.0-min.gz.js

HTTP/1.1 200 OK
Content-Type: application/javascript
Content-Length: 23239
Connection: keep-alive
Date: Sun, 31 Dec 2017 09:26:40 GMT
Last-Modified: Tue, 21 Nov 2017 00:55:32 GMT
ETag: "5e5fd363385b443a1776809d988fc9bb"
Cache-Control: max-age=604800
Content-Encoding: gzip
Accept-Ranges: bytes
Server: AmazonS3
Age: 238843
X-Cache: Hit from cloudfront
Via: 1.1 671f0d6e0d2ebbc109dd74f759a93a75.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 1OCy2RQtH-0_ycCxWMpOLuaz1zuFVUFR3ZHwREKW2xAsVmrwviP5KQ==

If Access-Control-Allow-Origin: * header is given, we can reach out error detail instead of barely getting Script error.

Adding this header would give huge convenience for debugging.

Please consider this,
Thanks!

Importing amplitude results in empty object

Hi. First, thanks for your work and this awesome library.

Since 3 days, doing:

import amplitude from 'amplitude-js/amplitude.min';

console.log(amplitude);

with this in package.json:

"amplitude-js": "github:amplitude/Amplitude-Javascript",

outputs:

{}

A temporary fix:

"amplitude-js": "github:amplitude/Amplitude-Javascript#0b103b3",

Thanks in advance!

ReferenceError: window is not defined

Trying to use amplitude-js on node 8.8.1

I got this error when I run: const amplitude = require('amplitude-js');

ReferenceError: window is not defined
    at /root/app/node_modules/amplitude-js/amplitude.js:2427:8
    at commonjsGlobal (/root/app/node_modules/amplitude-js/amplitude.js:2:82)
    at Object.<anonymous> (/root/app/node_modules/amplitude-js/amplitude.js:5:2)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/app/src/helpers/amplitude.js:3:19)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
...

Async bugs caused by missing logEventWithGroups in snippet

It seems that logEventWithGroups is missing from your <script> snippet, both here in this repo and in the Amplitude UI where you show the installation snippet (that one is also an old 3.0.1 script version).

Not having logEventWithGroups may work sometimes, but causes intermittent and hard-to-debug async problems (especially in our single-page app) where a page may break if analytics is called before the async script has actually loaded.

It seems that the new logEventWithTimestamp function is also missing from the snippet.

Register a package with Bower

I've been using Bower to manage packages and was disappointed not to find Amplitude.

I'm happy to create a pull request if there's no reason not to do this.

`window.amplitude.getInstance()` is not a function...

Hello,

I'm using the latest Amplitude snippet given in the Amplitude Dashboard, and when I call amplitude.getInstance(), I get Uncaught TypeError: window.amplitude.getInstance is not a function

Is the version of the snippet served from the Dashboard old? When I checkout the 2.9.0 tag on GitHub, I don't see the getInstance definition.

Any help is appreciated.

Many utm warnings

When we set options includeUtm and includeReferrer to true, and when url does not have any query params, Amplitude make many console.logs:

[Amplitude] WARNING: Property key "initial_utm_source" with invalid value type undefined, ignoring
amplitude-2.11.0-min.gz.js:1 [Amplitude] WARNING: Property key "initial_utm_medium" with invalid value type undefined, ignoring
amplitude-2.11.0-min.gz.js:1 [Amplitude] WARNING: Property key "initial_utm_campaign" with invalid value type undefined, ignoring
amplitude-2.11.0-min.gz.js:1 [Amplitude] WARNING: Property key "initial_utm_term" with invalid value type undefined, ignoring
amplitude-2.11.0-min.gz.js:1 [Amplitude] WARNING: Property key "initial_utm_content" with invalid value type undefined, ignoring

The problem appeared since 2.11.0. Now we use 2.10.0 to eliminate logs.
It is a bug? Or there is a 'proper-oficial' way to disable warnings?

Cannot read property 'hasOwnProperty' of undefined

The following code is supposed to be pasted in every page that uses amplitude:

(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script");r.type="text/javascript"; r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.0.1-min.gz.js"; r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0]; i.parentNode.insertBefore(r,i);function s(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0))); return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"]; for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this; };var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]; for(var l=0;l<p.length;l++){s(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId"]; function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0))); }}for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){e=(!e||e.length===0?"$default_instance":e).toLowerCase(); if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]};e.amplitude=n; })(window,document);

There is however this issue:

Cannot read property 'hasOwnProperty' of undefined

which can be found being called near the end of the amplitude code pasted above. If anyone else has run into this issue and knows how to solve it, any help would be appreciated.

JS error on load if browser blocks access to localStorage

If the user set their browser to block local storage, there's an uncaught exception when the Amplitude JS SDK is loaded.

This is the error I get in Chrome when setting it to "Block sites from setting any data":
Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

This is the line where Amplitude tries to access window.localStorage without a try-catch:
https://github.com/amplitude/Amplitude-Javascript/blob/fddc4eb630fb2fe9b42b0f11dcda1fc827cad4cb/src/localstorage.js#L8

Batching + callback?

The documentation is pretty clear that In the case that batchEvents is true, if the batch requirements eventUploadThreshold and eventUploadPeriodMillis are not met when logEvent is called, then no request is sent, but the callback is still called -- however I want to ask if there is any way to get around that and force-send the request?

In general for the events on my app itself, I want to batch my events for the user maneuvering around the app, etc -- but if they tap an external link, I need to send the request to amplitude to log that event (and ideally any other batched events) and wait for the callback before setting the new window.location. Is there any way to make this work? My apologies if I missed something in the documentation...

Opera blocking amplitude by default

Well, I've just found that new Opera has built-in adblock and when it is activated it blocks most of the tracking scripts, including Amplitude ofc, Sentry, Google Analytics etc.

Do you have by any chance some workaround for it? Or do you know whats the exact reason (some script characteristics or whatever) behind that?

amplitude.getInstance().options.deviceId sometimes undefined

Is there a way to get the device ID via a callback?

In the documentation, only amplitude.getInstance().init() is shown to have a callback, but we initialize amplitude in a different part of the code from where we get the device ID and I'm not sure if you can call init() more than once.

Thanks for your help.

React Native (non browser) support

This project relies on usage of 'document' and is such not compatible with react-native. Could this be abstracted out so this package can be used in a react native project without the usage of a native module?

Purpose of JSON module

Hi there, I don't get what is the purpose of using some JSON module since you use only parse and stringify functions. We already have window.JSON in javascript and it does the job well.
Even if you need the module because you're running your code in some environments different from browser or Node you should have noticed it in the package.json

Log level options

Since the log used by Amplitude is just a facade to console.log (as seen here https://github.com/amplitude/Amplitude-Javascript/blob/master/src/utils.js#L4) It would be nice if the log level can be parameterized and optional (a simple logLevel:WARN|ERROR|NONE in options works great)

We are using a very flexible model to some trackings, and principally the log [Amplitude] WARNING: Property key "some-key" with invalid value type null, ignoring is just sending trash to our console and our log monitoring.

Do you intend to create some kind of feature like this?

setDeviceId conflicts with includeUtm

Hi,

I noticed that if initialize amplitude with includeUtm and then call setDeviceId with a custom device ID, it seems that utm_source parameters are no longer tracked. As long as I don't call setDeviceId after initialization, utm_source parameter tracking works fine.

Here's my sample code snippet:

  amplitude.getInstance().init('AMPLITUDE_API_KEY', null, {
    includeUtm: true,
    includeReferrer: true,
    includeGclid: true
  });
amplitude.getInstance().setDeviceId('DEVICE_ID')

I'm not sure if this is a bug or intended behavior, but if you could help advise how I can retain tracking utm_source parameters and set device id after initialization, that'd be greatly appreciated. (Unfortunately, passing a deviceId parameter to the init function is not an option atm.

Thanks,
Henry

Error processing events queued during install

Our amplite.init() call and the snippet are in the head of our document and afterwards from other .js files we call logEvent. This gives the console error:

[Amplitude] apiKey cannot be undefined or null, set apiKey with init() before calling logEvent()

Since it's higly unlikey we should block the whole app to wait for the init callback, we sucpect this is a problem with the queue that is mentioned here: #18 (comment)

setUserProperties callback

Hey guys, is there any callback event for the setUserProperties method? like there's for LogEvent, Identify, and Redirect?

If not, any intentions to implement it?

thanks!

Publish to NPM

Please and thank you.

I would like to use this as a dependency in npm without having to rely on github. Thanks for your time.

Only first event logged / sent to server

I integrated amplitude-javascript into my Angular/Ionic app using this method: https://github.com/mounibec/angular-amplitude.

I'm experiencing a strange behavior: if I turn on the $locationChangeStart listener, the first event (first route change) is correctly sent to the server (I'm monitoring api.amplitude.com calls). But all subsequent events are not sent (no errors). If I turn off the listener and send some events manually, same behavior: only the first logEvent is logged.

I noticed the _q property of the amplitude object is correctly appended w/ new event data after the first one. In local storage, amplitude_unsent stays empty and amplitude_lastEventId stays the same.

FIY I'm using the same integration on another angular app (w/o Ionic though) and it's working fine with the $locationChangeStart listener.

Any idea as to why or how to debug this?

Thanks.

Submitting Arrays via Event Properties

Heyo there, Amplitude seems quite nice, the SDK is also easy to use!

I have stumbled upon an issue though, I believe. I wanted to submit an Array of strings via the custom event properties but it doesn't seem to show up in the Amplitude interface.

Seems like the array gets discarded?

Screenshots:

1

2

amplitude-js v3.7.0 breaks my CI build with an undefined reference

Here's an excerpt from the traceback

node_modules/amplitude-js/amplitude.js:67
    var objectProto = Object.prototype,
                            ^
TypeError: Cannot read property 'prototype' of undefined
    at runInContext (node_modules/amplitude-js/amplitude.js:67:29)
    at Window.<anonymous> (node_modules/amplitude-js/amplitude.js:886:5)
    at node_modules/amplitude-js/amplitude.js:919:4
    at createCommonjsModule (node_modules/amplitude-js/amplitude.js:14:35)
    at node_modules/amplitude-js/amplitude.js:17:13
    at commonjsGlobal (node_modules/amplitude-js/amplitude.js:2:82)
    at Object.<anonymous> (node_modules/amplitude-js/amplitude.js:5:2)
    ...

This seems to happen at require, so I don't think that there's anything I can do about it. My tests are running under mocha with jsdom if that makes any difference.

Previously, my package.json had "amplitude-js": "^3.6.0". In order to resolve this issue for the time being, I've been forced to lock myself at the previous version ("amplitude-js": "=3.6.0") which is obviously not ideal.

It looks like the changes between 3.6 and 3.7 are pretty significant and do touch the lines that my build is complaining about.

Let me know if you need any further details.

Integrate Amplitude with Tealium

Dear all ,

I want to use the JS SDK with Tealium , and i want to know if there is any doc that could guide/help me please.

Regrads

uniquely identifying events

I'm trying to figure out how to uniquely identify events that I'm tracking. I've read about custom user IDs, but it seems like that is used to uniquely identify the user, not the event. At the moment, I really care about uniquely identifying events. For example...

Let's say we have an event called TRANSFER with a property called status. If a user fires TRANSFER many times with status set to something different for each event, it seems like all of the events will be treated as one unique event. However, I need all of the events to be considered unique.

How can I do this?

AngularJS - Service not acting as singleton

Hello all, so I am using this wrapper for the Amplitude JS API in my Angular application and as it is heavily related to this project, I figured I might as well ask here. Also, it is my hope that hopefully this will catalyze more support/documentation for using AmplitudeJS in an AngularJS application.

Apologies for the code heavy post but I wanted to provide as much context as possible. I am having an issue with defining Amplitude as a service in my Angular.js application. Services are supposed to act as singletons throughout an application (source), so I am confused to be getting the following behavior.

In my app.js file, I call AmplitudeService.logEvent('EVENT_NAME') in a .run function which successfully logs the event to Amplitude. Note: Console.log(AmplitudeService) returns an object with all the correct functions here.

However, when I call AmplitudeService.logEvent('EVENT_NAME') within any other controller, (header.js file in this example) I do not ever see any data in my Amplitude dashboard. Note: Console.log(AmplitudeService) within header.js returns an identical object to the one returned from app.js

Would appreciate any and all insight!

AmplitudeService.js (source)

Note: If you check the author's syntax, he returns an object at the end of his service. In my research, I've read to use the "this" keyword when defining Service functions (source), and that you don't need to return an object as you would with a Factory, so I have updated it accordingly.

    angular.module('AmplitudeService', [])
    .service('AmplitudeService', 
    ['$amplitude', '$rootScope', 'amplitudeApiKey', '$location',
    function ($amplitude, $rootScope, amplitudeApiKey, $location) {

      this.init = function() {
        $amplitude.init(amplitudeApiKey, null);
      }

      this.identifyUser = function(userId, userProperties) {
        $amplitude.setUserId(userId);
        $amplitude.setUserProperties(userProperties);
      }

      this.logEvent = function(eventName, params) {
        $amplitude.logEvent(eventName, params);
      }
    }]);

angular-amplitude.js (source)

This allows access to "$amplitude" throughout the application

```
(function(){
var module = angular.module('angular-amplitude', ['ng']);

module.provider('$amplitude', [function $amplitudeProvider() {
this.$get = ['$window', function($window) {
  (function(e,t){
    var r = e.amplitude || {};
    var n = t.createElement("script");
    n.type = "text/javascript";
  n.async = true;
  n.src = "https://d24n15hnbwhuhn.buttfront.net/libs/amplitude-2.2.0-min.gz.js";
  var s = t.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(n,s);
  r._q = [];

  function a(e){
    r[e] = function(){
      r._q.push([e].concat(Array.prototype.slice.call(arguments,0)));
    }
  }
  var i =    ["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties"];
  for(var o = 0; o < i.length; o++){
    a(i[o])
  }
  e.amplitude = r
}
  )(window,document);
  return $window.amplitude;
}];
}]);
return module;
}());
```

App.js

```
angular.module('app', [
'ngRoute',
'angular-amplitude',
'AmplitudeService',
])

 .run(['AmplitudeService', function(AmplitudeService){
 console.log(AmplitudeService); // Outputs 'Object {}'
 AmplitudeService.init();
 *AmplitudeService.logEvent('LAUNCHED_SITE'); // This logs the event*
 console.log(AmplitudeService); // Outputs 'Object {}'
 }])
```

Header.js

 ```
 angular.module('app.common.header', [])
 .controller('HeaderCtrl', [ '$rootScope', '$scope', '$location','$route', '$window', 'AmplitudeService', function($rootScope, $scope, $location, $route, $window, AmplitudeService){

 $scope.goToSearch = function(term) {
 $location.path('/search/' + term);
  console.log(AmplitudeService); // Outputs 'Object {}'
*AmplitudeService.logEvent('SEARCHED');* // This does not log the event
 };
 }]);
 ```

If anyone has any experience implementing Amplitude JS in their Angular app, would love to hear from you. Thanks.

OS Property does not distinguish between Mobile Browser vs Webview Browser

Hi,

When inspecting the OS property for web events, it appears that Amplitude is treating Chrome/Safari Webviews as the same OS as the normal Chrome/Safari Browsers.

Would it be possible to consider mobile webview browsers separately from the standard mobile browsers? This is because certain interactions/rendering/session management behave differently between webviews and mobile browsers and we need to be able measure our conversion rate on standard browsers versus in-app webviews.

I did a quick test and it seems that we are able to distinguish between mobile browsers and webviews using the user agent: https://faisalman.github.io/ua-parser-js/

Thanks for your help,
Henry

UTM and Referrer data are lost after refresh browser.

When the browser is refreshed the UTM & Referer data are lost (not loaded, either recovery).
The issue is in L594.

There is a check for the sessionId, lastEventTime and sessionTimout, and they exists because they are saved to the amplitude cookie. But the UTM & Referrer data aren't saved in any place.

The cookie has something like this

{
  "deviceId":"2a9b9f90-6006-411a-87e0-b33a5c996a71R",
 "userId":null,
  "optOut":false,
 "sessionId":1494897660205,
  "lastEventTime":1494898093183,
  "eventId":0,
  "identifyId":1,
  "sequenceNumber":1
}

Let me know when the fix is ready to update the version on the snipped.

Thanks! :)

Issue with using Amplitude via <script> tag and AMD

Hello,

I'm using AMD on my website (Require.js) to load my scripts. I use the R Optimizer to compile everything into a single javascript file.

However, Amplitude is loaded via a <script> tag (actually async via Segment.io). I have no way to load Amplitude differently.

This line then crashes my app:

https://github.com/amplitude/Amplitude-Javascript/blob/master/amplitude.js#L5

Here you can see the error in my console (Mac OS X 10.10, Chrome 40):

capture d ecran 2015-01-27 a 12 35 02

As http://requirejs.org/docs/errors.html#mismatch explains, it seems to be caused by the anonymous define() call.

Thanks a lot, I'll be happy to test some more if it can be helpful.

no https/encryption transport option

There doesn't seem to be an option where POSTs to record data to amplitude servers are done via HTTPS. This seems like a pretty basic feature but I was surprised to see its only using HTTP and doesn't mention an encryption transport option anywhere. Can you please let me know about this.

Track Referrer Not Working

Hey friends over at Amplitude!

My name is Alex and I am a Success Engineer at Segment. Looking into a issue for a mutual customer of our it appears the trackReferrer option is not adding information as a user property in Amplitude. After enabling the integration in our testing suite and verifying that it was set to true in the console and firing several different calls I was unable to see the referrer as the user property in the Amplitude dashboard.

Has anything been updated or changed recently? Just trying to get to the root of this for a mutual customer of ours.

Cheers!

Use of navigator `sendBeacon`?

Hi,

Would you consider using navigator.sendBeacon when available (modern browsers) rather than xhr requests? The advantages are:

  • offline support (events are queued if loss of connectivity)
  • execution in a worker thread
  • page unloads doesn't cancel in-flight requests

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.