https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
b

brave-jelly-4060

02/28/2024, 3:10 AM
Hi! We're trying to use the pre-built script tag with Webflow + Rudderstack as our eventing system. However, it doesn't appear that trackingCallback is firing, as we added in a console.log that's not showing up. Will post the code in the thread. We've gotten it working previously without using the pre-built script tag, so not sure if I'm just missing something super obvious and thought I'd ask 🙂
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

fresh-football-47124

02/28/2024, 5:59 AM
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

brave-jelly-4060

02/28/2024, 6:42 AM
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

fresh-football-47124

03/01/2024, 3:56 AM
it could be
b

brave-jelly-4060

03/06/2024, 5:07 AM
@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 🙂
8 Views