Firing static event (JS Snipper) - with dynamic user data - is this possible? (we use segment.com)

Hi there,

We use segment.com in our original implementation, which we wish to remain with.

I was able to easily fire an identify call/event with static events with an example, but, I’ll need to pull in database data such as UserID, email address etc. into each JS snippet.

Is using static events the correct way to do such, and will I just need to manually type in the dynamic binding code for each data I want to push through with the JS?

This is the example JS:

analytics.identify("97980cfea0067", {
 name: "Peter Gibbons",
 email: "peter@example.com",
 plan: "premium",
 logins: 5
});

So I need to replace the number, name, email, plan etc. with dynamic data on login / sign up. I’ve tried replicating what I have working in static events in dynamic running JS from flow, but that isn’t working.

Not sure on the use of segment.com but if this is using custom JS you’ll need to make use of the dmx.parse() and dmx.app.set() functions/methods.

Damn. I’m trying really hard to do everything Wappler first for easier future maintainability- seems like this should be a relatively easy thing to do with the tools at Wappler disposal. Static Event is perfect for this I just don’t know if it’s possible to include dynamic data. @Teodor?

There are ways to call vanilla js with dynamic data.

Here’s a couple I have used:

  1. Within the javascript, use dmx.app.data… or dmx.parse("") to get dynamic data.

  2. Use a dynamic event by modifying the syntax.

For example, calling myFunction() from a static event, becomes myFunction({{null}}) in a dynamic event.

Or another: mainView is not an object in Wappler, but I want to use the list_id from a Wappler repeat:

dmx-on:click="mainView.router.navigate('/user_list/{{list_id}}/')"

Although static events and dmx.parse would work for this use case, I would recommend you to use FLOW instead.
Create an app level flow with params such as ‘name’, ‘email’ etc. and add 1 step - Run Javascript. In that step call a custom JS function, and pass all the flow-params as params to this JS call.

In your JS function, configure the analytics code using those parameters.

Now, wherever you need to call this analytics code, in the onsucess or similar dynamic event, you can just run the FLOW and pass all required params from server connect or form.

This is pretty much same as using static event & dmx.parse, but its much easier to maintain since the heavy lifting can be done using the UI action pickers, and the code view remains cleaner.

Although, there is one bug with the UI, awaiting a fix: Flow Param Not Showing in Action Picker Load Event
You can configure it via code view until this is fixed.

Hey @sid - thank you for the reply.

I did check out FLOW, my problem being I have very limited JS knowledge at this point - I got a little lost with how to setup the JS parameters.

I tried adding and running the JS trigger ( as defined by Segment, and the same trigger that works 100% when using a static event) - but I kept getting errors, so put it down to my lack of knowledge as to how to create the JS snippet with the run JS action.

Thank you for your input, this guides me to know that using FLOW is the best way to do this - I just need to figure out the JS part, now!