Skip to content

Instantly share code, notes, and snippets.

@marinhero
marinhero / wootric_events.js
Created February 4, 2020 18:49
An example on how to set events inside the Wootric SDK to use targeted sampling
// You define a global variable to track your events
my_global_event_name = 'loaded_website';
// You define your WootricSettings variable at the beginning of the code
wootricSettings = {
account_token: 'NPS-YOURTOKEN',
email: 'user@example.com',
created_at: 1528416000,
properties: {
favorite_color: 'blue'
<script type="text/javascript">
window.wootricSettings = {
email:'nps@example.com',
created_at: 1528416000,
product_name: 'HUBSPOT NPS',
account_token: 'NPS-xxxxxxxx',
properties:{
pricing_plan:'pro',
favorite_color: 'red'
}
@marinhero
marinhero / exclude_domains.js
Created May 20, 2019 20:16
Do not survey certain domains
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdn.wootric.com/wootric-sdk.js"></script>
<script type="text/javascript">
var user_email = user.email; // Mocking a backend object
var blackListedDomain = 'wootric.com';
if (user_email.indexOf(blackListedDomain) != -1) {
window.wootricSettings = {
version: '3.1'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.3.3
hostname: elasticsearch
ports:
- 9210:9200
- 9310:9300
environment:
@marinhero
marinhero / script.sh
Created November 29, 2018 01:07
Sampling Settings Override Example
# General example with all params
curl -X POST \
https://api.wootric.com/v1/email_survey \
-H 'Authorization: Bearer YOUR-TOKEN' \
-F 'emails[]=marin@wootric.com' \
-F 'survey_settings[sampling][response_throttle]=0' \
-F 'survey_settings[sampling][registered_percent]=100' \
-F 'survey_settings[sampling][first_survey_delay]=0' \
-F 'survey_settings[sampling][decline_throttle]=1'
//Test flags. Remove before going live!
wootric_survey_immediately = true;
wootric_no_surveyed_cookie = true;
//This is an example of a user object. You'll have to adjust the example to your own user object or data.
var current_user = {
user_email: 'marin@woot.com',
dashboard_language: 'EN',
registration_date: 1496880000
};
<!-- begin Wootric code -->
<script type="text/javascript">
wootric_survey_immediately = true; //TODO:comment this in production
window.wootricSettings = {
email:'nps@example.com', //TODO: Required to uniquely identify a user. Email is recommended but this can be any unique identifier.
created_at: 1234567890, //TODO:replace it with date when your customer signed up
account_token: 'NPS-XXXX', //TODO:replace it with your account token
properties: {} //Make sure you initialize it, with or without values.
};
</script>
@marinhero
marinhero / traverse_tokens.js
Created March 2, 2018 01:40
Traverse tokens recursively
//Only eligible in second account
var token_list = ['NPS-5cb686c1', 'NPS-8296bf77'];
var wootricSettings = {
account_token: ''
};
//wootric_survey_immediately = true;
//wootric_no_surveyed_cookie = true;
@marinhero
marinhero / custom_samplings_generator.rb
Created March 1, 2018 23:06
custom_samplings_generator.rb
#
# Open rails console
# type: load 'custom_samplings_generator.rb'
# type: seed('NPS-YourToken')
# Go to /account_sampling_rules.json?account_token=NPS-YourToken in Survey Server
#
RULES = %w(
on_click
on_login
<html>
<head>
<meta http-equiv="Content-Security-Policy"
content="connect-src https://*.wootric.com;
script-src 'nonce-EBVmWKEBEP' 'nonce-iApyYLoklC' 'strict-dynamic';
object-src 'none';
base-uri 'none';
img-src 'self' data;
font-src 'self' data:;" />