I'm wondering why I have to include the JavaScript cxApi when I'm running the experiments server-side. Furthermore, can I send the chosen experiment and variations by PHP? Or maybe by injecting a JavaScript snippet without external resources (like the cxApi).
I'm using Universal Analytics on the front-end and on the back-end.
Take a look at this library: php-gacx (Server-Side Google Analytics Content Experiments PHP Client) https://github.com/thomasbachem/php-gacx
They parse cxApi response on server-side and update cxApi cookie. Also take a look at this comment: https://github.com/thomasbachem/php-gacx/issues/4
hope it helps
Alternative approach: You can do randomization yourself and just set GA custom dimensions "expId" and "varId" with ga('set',...) syntax and then send any hit (i.e. pageview). https://developers.google.com/analytics/solutions/experiments-server-side
Here is nice article how to do weight-based randomization: http://codetheory.in/weighted-biased-random-number-generation-with-javascript-based-on-probability/