Skip to content

Commit

Permalink
Merge branch 'bower-snippet'
Browse files Browse the repository at this point in the history
  • Loading branch information
tdumitrescu committed Feb 20, 2015
2 parents ab37e18 + 3cdab5c commit 31c0055
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Mixpanel JavaScript Library

The Mixpanel JavaScript Library is a set of methods attached to a global `mixpanel` object
intended to be used by websites wishing to send data to Mixpanel projects. A full reference
is available [here](https://mixpanel.com/help/reference/javascript).

## Alternative installation via Bower
`mixpanel-js` is also available via front-end package manager [Bower](http://bower.io/). After installing Bower, fetch into your project's `bower_components` dir with:
```sh
bower install git://github.com/mixpanel/mixpanel-js.git
```
(TODO: update Bower address after registration as `mixpanel`)

### Using Bower to load the snippet
You can then load the lib via the embed code (snippet) with a script reference:
```html
<script src="bower_components/mixpanel-js/mixpanel-jslib-snippet.min.js"></script>
```
which loads the _latest_ library version from the Mixpanel CDN ([http://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js](http://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js)).

### Using Bower to load the entire library
If you wish to load the specific version downloaded in your Bower package, there are two options.

1) Override the CDN library location with the global `MIXPANEL_CUSTOM_LIB_URL` var:
```html
<script>
window.MIXPANEL_CUSTOM_LIB_URL = 'bower_components/mixpanel-js/mixpanel.js';
</script>
<script src="bower_components/mixpanel-js/mixpanel-jslib-snippet.min.js"></script>
```
or

2) Recompile the snippet with a custom `MIXPANEL_LIB_URL` using [Closure Compiler](https://developers.google.com/closure/compiler/):
```sh
java -jar CLOSURE_COMPILER_JAR_FILE_LOCATION --js mixpanel-jslib-snippet.js --js_output_file mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="bower_components/mixpanel-js/mixpanel.js"'
```
19 changes: 19 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "mixpanel-js",
"homepage": "https://github.com/mixpanel/mixpanel-js",
"description": "Mixpanel JavaScript Library",
"main": "mixpanel-jslib-snippet.js",
"repository": {
"type": "git",
"url": "git@github.com:mixpanel/mixpanel-js.git"
},
"keywords": [
"mixpanel",
"mixpaneljs",
"mixpanel-js"
],
"license": "Apache-2.0",
"ignore": [
"tests"
]
}
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ java -jar $1 --js mixpanel.js --js_output_file mixpanel.min.js --compilation_lev
%output%
})();"

java -jar $1 --js mixpanel-jslib-snippet.js --js_output_file mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS --define='LIB_URL="//cdn.mxpnl.com/libs/mixpanel-2.2.js"'
java -jar $1 --js mixpanel-jslib-snippet.js --js_output_file mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS

5 changes: 2 additions & 3 deletions mixpanel-jslib-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// ==/ClosureCompiler==

/** @define {string} */
var LIB_URL = '../mixpanel.js';
var MIXPANEL_LIB_URL = '//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js';

(function(document, mixpanel){
// Only stub out if this is the first time running the snippet.
Expand Down Expand Up @@ -69,8 +69,7 @@ var LIB_URL = '../mixpanel.js';
script.type = "text/javascript";
script.async = true;

// The default url is intended to be relative to the tests/tests.html file
script.src = LIB_URL;
script.src = typeof MIXPANEL_CUSTOM_LIB_URL !== 'undefined' ? MIXPANEL_CUSTOM_LIB_URL : MIXPANEL_LIB_URL;

first_script = document.getElementsByTagName("script")[0];
first_script.parentNode.insertBefore(script, first_script);
Expand Down
2 changes: 1 addition & 1 deletion mixpanel-jslib-snippet.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31c0055

Please sign in to comment.