Skip to content

Instantly share code, notes, and snippets.

@dwightgunning
Created July 30, 2013 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwightgunning/6088c0b0056838c0eb47 to your computer and use it in GitHub Desktop.
Save dwightgunning/6088c0b0056838c0eb47 to your computer and use it in GitHub Desktop.
Attempt at loading mixpanel with AMD.
/*global require*/
'use strict';
require.config({
baseUrl: "/media_static/js",
dir: "../media_static",
urlArgs: "bust=" + (new Date()).getTime(),
modules: [
{
name: "public-main"
}
],
paths: {
underscore: '../vendor/js/underscore/underscore',
jquery: '../vendor/js/jquery/jquery-1.9.1',
mixpanel: '../vendor/js/mixpanel/mixpanel-2.2.min',
},
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
underscore: {
exports: '_'
},
mixpanel: { //make sure you have a path config for the snippet
exports : 'mixpanel',
},
},
});
define('mixpanel-snippet', ['mixpanel'], function(mixpanel){
console.log('defining snippet');
var e = document, b = mixpanel;
if (!b.__SV) {
var i, g;
window.mixpanel = b;
b._i = [];
b.init = function (a, e, d) {
function f(b, h) {
var a = h.split(".");
2 == a.length && (b = b[a[0]], h = a[1]);
b[h] = function () {
b.push([h].concat(Array.prototype.slice.call(arguments, 0)))
}
}
var c = b;
"undefined" !==
typeof d ? c = b[d] = [] : d = "mixpanel";
c.people = c.people || [];
c.toString = function (b) {
var a = "mixpanel";
"mixpanel" !== d && (a += "." + d);
b || (a += " (stub)");
return a
};
c.people.toString = function () {
return c.toString(1) + ".people (stub)"
};
i = "disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");
for (g = 0; g < i.length; g++)
f(c, i[g]);
b._i.push([a, e, d])
};
b.__SV = 1.2
}
console.log('initialising mixpanel');
mixpanel.init("5460b8592b69b220ab121dc591a72774");
return mixpanel;
});
require([
'jquery',
'mixpanel-snippet',
], function ($, mixpanel) {
mixpanel.track("Landing Page");
});
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Test Landing Page</title>
</head>
<body>
This is a test page.
</body>
<script src="/media_static/vendor/js/require/require.js" data-main="/media_static/js/public-main.js"></script>
</html>
@welcoMattic
Copy link

Hi, i've got the same issue as you.

Try to add 'jquery' here :

define('mixpanel-snippet', ['mixpanel', 'jquery'], function(mixpanel){

Let me know if it's works

@mohitmayank
Copy link

solved. your's is a private gist. so i added a public one https://gist.github.com/mohitmayank/6162576

@abhoopathy
Copy link

welcoMattic, I think you have a mixpanel ID in your source on line 70. Not sure if that's intentional, but you may want to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment