Plugin works in preview, NOT works in exported game

For developers using the Construct 2 Javascript SDK

Post » Wed Mar 22, 2017 9:36 am

Hi,

I am trying to develop a plugin for Gameanalytics.com
I am using :
https://github.com/orange-games/GA-JavaScript-SDK

The problem is that the plugin I developed works perfect in preview mode but not on the exported version.
The exported version works on itch.io website (still gives an error about crypto.js- a file the is placed on dependency) but doesn't on bitballoon.com

The problem can be at the fact that the plugin needs 7 files listed on dependency?

Code: Select all
"dependency":   "cryptojs.d.ts;enc-base64-min.js;GaJavaScriptSdk.d.ts;GaJavaScriptSdk.js;GaJavaScriptSdk.js.map;GaJavaScriptSdk.min.js;hmac-sha256.js;"
   

on runtime.js:

Code: Select all
//init
   Acts.prototype.init= function(gameKey, secretKey,build)
   {
   var user = new GA.User();
    //Create an instance
    var gaan = GA.getInstance();
   
   gaan.init(gameKey, secretKey, build, user)
            .addEvent(new GA.Events.User())
            .addEvent(new GA.Events.Design('Game:Start'));
   };
   
   //end init


Can anyone with more experience in developing plugins can help me?

Thanks
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Wed Mar 22, 2017 9:51 am

There are 2 possible solutions:
1. export project without "Minify"
2. use ["prop"] instead of .prop . For example:
GA.User -> window["GA"]["User"]
gaan.init --> gaan["init"]
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Wed Mar 22, 2017 12:30 pm

Thanks, I fixed it. It seams that the order of dependency assets does matter
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Wed Mar 22, 2017 3:56 pm

It seams that now the plugin works only without minify.
With minify option it doesn't work

I tried to rewrite the code as follows but I guess I did it wrong:
@rexrainbox
Can you see something wrong here:

Code: Select all
/*
   var user = new GA.User();
    //Create an instance
    var gaan = GA.getInstance();
   
   gaan.init(gameKey, secretKey, build, user)
            .addEvent(new GA.Events.User())
            .addEvent(new GA.Events.Design('Game:Start'));
   };
   */
   
   var user = window["GA"]["User"];
    //Create an instance
    var gaan = window["GA"]["getInstance"];
   
   gaan["init"](gameKey, secretKey, build, user)
            .addEvent(window["GA"]["Events"]["User"])]
            .addEvent(window["GA"]["Events"]["Design('Game:Start')"])];
   };
   
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Wed Mar 22, 2017 4:06 pm

var user = new GA.User();
-->
var user = new window["GA"]["User"]();
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Wed Mar 22, 2017 4:14 pm

@rexrainbox
Thanks

and for:
gaan.init(gameKey, secretKey, build, user)
.addEvent(new GA.Events.User())
.addEvent(new GA.Events.Design('Game:Start'));

-> ???
B
33
S
8
G
4
Posts: 155
Reputation: 3,752

Post » Thu Mar 23, 2017 5:11 am

gaan["init](...)["addEvent"](new window["GA"]["Events"]["User"]())["addEvent"]](new window["GA"]["Events"]["Design"](...))


plugin-developers-please-test-with-the-minifier_t63774
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Thu Mar 23, 2017 1:37 pm

Thanks. It works
B
33
S
8
G
4
Posts: 155
Reputation: 3,752


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest