<commit_before>/*
 * We use dart:js to use the native JS mixpanel object.
 * 
 * See the following docs for more information:
 * https://www.dartlang.org/articles/js-dart-interop/
 */

library mixpanel;

import 'dart:js';
import 'package:mixpanel/mixpanel_api.dart';

class MixpanelError extends Error {
  String _message;
  MixpanelError(this._message);
  String toString() => 'MixpanelError: $_message';
}

class Mixpanel extends MixpanelAPI {
  JsObject _mixpanel;
  
  Mixpanel() {
    _mixpanel = context['mixpanel'];
    if (_mixpanel == null) {
      throw new MixpanelError(
          'Make sure you include the Mixpanel JS code inside the <head> and '
          '</head> tags. See the INSTALL section for more information.');
    }
  }

  @override
  void track(String event_name, {Map properties, Function callback}) {
    JsObject jsProperties =
        (properties == null ? null : new JsObject.jsify(properties));
    _mixpanel.callMethod('track', [event_name, jsProperties, callback]);
  }

  @override
  void track_links(String css_selector, String event_name, {var properties}) {
    if (properties is Map) {
      JsObject jsProperties =<commit_msg>Added a null check for callback and initialize it to an empty function.  The latest mixpanel js appears to call the callback without checking for null.<commit_after>/*
 * We use dart:js to use the native JS mixpanel object.
 * 
 * See the following docs for more information:
 * https://www.dartlang.org/articles/js-dart-interop/
 */

library mixpanel;

import 'dart:js';
import 'package:mixpanel/mixpanel_api.dart';

class MixpanelError extends Error {
  String _message;
  MixpanelError(this._message);
  String toString() => 'MixpanelError: $_message';
}

class Mixpanel extends MixpanelAPI {
  JsObject _mixpanel;
  
  Mixpanel() {
    _mixpanel = context['mixpanel'];
    if (_mixpanel == null) {
      throw new MixpanelError(
          'Make sure you include the Mixpanel JS code inside the <head> and '
          '</head> tags. See the INSTALL section for more information.');
    }
  }

  @override
  void track(String event_name, {Map properties, Function callback}) {
    JsObject jsProperties =
        (properties == null ? null : new JsObject.jsify(properties));
    if(callback == null) {
        callback = (a,b) {};
    }
    _mixpanel.callMethod('track', [event_name, jsProperties, callback]);
  }

  @override
  void track_links(String css_selector, String event_name, {var properties}) {
    if (properties is Map) {
      JsObject jsProperties =
{'fraction_non_alphanumeric': 0.10545023696682465, 'fraction_numerical': 0.0, 'mean_word_length': 3.572202166064982, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3779965', 'n_tokens_mistral': 757, 'n_tokens_neox': 744, 'n_words': 239}