Adding Trigger Events for Notifications and On Site Messages

Trigger events can be added to your site very simply using the event method of the xtremepush web SDK. 

xtremepush('event', 'EVENT_NAME');

It is really easy to add events especially if you use a tag manager like google tag manager. In the examples below we will go through two sample events you might want to create a page view event and an event related to form submission.

Page View Event

In our simple page view example we demonstrate how an event can be sent when a user views a page. We have a contact page for which we want to have a contact page viewed event:

First we add a GTM trigger for a page view:

 

Then we hang a Tag off this trigger:

In the custom html for the tag we send the page view event:


xtremepush('event', 'contact.us.page.view');

Once the event has been fired for the first time, it will be visible in the event section of campaign creation if you start typing the event name:

 

 

Form Event

In our simple form submission example we demonstrate how an event can be sent when a user inputs the name "John Doe" in a contact form.

First we add a GTM trigger for forms:

 

Then we hang a Tag off this trigger:

 

In the custom html for the tag we grab the first name and last name fields and check if they equal John and Doe:



if (getFormField("input[name=fname]")== "John" && getFormField("input[name=lname]")== "Doe"){ xtremepush('event', 'john.doe'); } function getFormField(field_name){ var field = {{Form Element}}.querySelector(field_name); console.log(field); return field ? field.value : undefined; }

When the event condition evaluates as true we send the custom event "john.doe" using the xtrempush web SDK event method.

xtremepush('event', 'john.doe');

We can now use this event to trigger web push notification or onsite messages.

Have more questions? Submit a request

0 Comments

Article is closed for comments.