This message was deleted.
# ask-questions
w
This message was deleted.
b
Copy code
<script type="text/javascript">
!function () {
        "use strict"; var sdkBaseUrl = "<https://cdn.rudderlabs.com/v3>"; var sdkName = "rsa.min.js"; var asyncScript = true
                ; window.rudderAnalyticsBuildType = "legacy", window.rudderanalytics = []
                ; var e = ["setDefaultInstanceKey", "load", "ready", "page", "track", "identify", "alias", "group", "getAnonymousId", "getSessionId", "reset", "setAnonymousId", "startSession", "endSession"]
                ; for (var t = 0; t < e.length; t++) {
                        var n = e[t]; window.rudderanalytics[n] = function (e) {
                                return function () {
                                        window.rudderanalytics.push([e].concat(Array.prototype.slice.call(arguments)))
                                }
                        }(n)
                } try {
                        new Function('return import("")'), window.rudderAnalyticsBuildType = "modern"
                } catch (a) { }
        if (window.rudderAnalyticsMount = function () {
                "undefined" == typeof globalThis && (Object.defineProperty(Object.prototype, "__globalThis_magic__", {
                        get: function get() {
                                return this
                        }, configurable: true
                }), __globalThis_magic__.globalThis = __globalThis_magic__,
                        delete Object.prototype.__globalThis_magic__); var e = document.createElement("script")
                        ; e.src = "".concat(sdkBaseUrl, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkName), e.async = asyncScript,
                                document.head ? document.head.appendChild(e) : document.body.appendChild(e)
        }, "undefined" == typeof Promise || "undefined" == typeof globalThis) {
                var d = document.createElement("script")
                ; d.src = "<https://polyfill.io/v3/polyfill.min.js?features=Symbol%2CPromise&callback=rudderAnalyticsMount>",
                        d.async = asyncScript, document.head ? document.head.appendChild(d) : document.body.appendChild(d)
        } else {
                window.rudderAnalyticsMount()
        } window.rudderanalytics.load("xxxxxx", "<https://ownhomemigmk.dataplane.rudderstack.com>", {})
}();    
</script>

<script>
  window.growthbook_config = window.growthbook_config || {};
  window.growthbook_config.trackingCallback = (experiment, result) => {
    console.log("Tracking callback called.");
    if (rudderanalytics && rudderanalytics.track) {
      rudderanalytics.track("Experiment Viewed", {
        anonymous_id: rudderanalytics.getAnonymousId(),
        experiment_id: experiment.key,
        variation_id: result.key
      });
    } else {
      console.error("Rudderstack SDK or track method not available.");
    }
  };
  window.growthbook_config.attributes = {
    "anonymousId": rudderanalytics.getAnonymousId(),
    "sessionId": rudderanalytics.getSessionId()
  };
</script>
  
<script async
  data-api-host="<https://cdn.growthbook.io>"
  data-client-key="sdk-xxxx"
  src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.min.js>"
></script>
And the* public page*
f
Hi
How have you defined the experiment?
that trackingCallback looks right, if the trackingCallback doesn't fire, sometimes it from the assignment id not being set
b
The experiment is set up as a visual editor experiment using anonymous_id - may well have done something wrong in the set up. Having checked - there is a slight discrepancy in that in our targeting attributes in the SDK configuration, it's in camel case, and in the script above + query it's set in in snake case. Could this be the source of the issue?
f
it could be
b
@fresh-football-47124 - I think in the end it was the Rudderanalytics script not being fully initialised? Di you have recommendations for how to assign randomisation for a frontend marketing experiment on visitors (i.e. anonymous or device ID). as above, we're currently using the Rudderstack SDK's anonymous ID, but this does slow down the load due to the above, so we are open to switching to a different way of doing it 🙂
136 Views