Skip to content

Instantly share code, notes, and snippets.

View robisatthefunction's full-sized avatar

Robert Saunders robisatthefunction

  • Optimizely
View GitHub Profile
{
"schema_version": "1.0",
"agent_type": "specialized",
"name": "Get Experiments Report",
"output": {
"type": "text",
"schema": null,
"description": null
},
"version": "1.0.0",
function getTotalOrderAmount() {
let price = document.querySelectorAll('div > div.a-column.a-span2 > li > div:nth-child(2) > span')
let count = 0
price.forEach(function(element){
let priceString = element.innerHTML.replace('$', '');
let priceFloat = parseFloat(priceString);
count += priceFloat;
});
return count;
}
// Inject Optimizely script immediately
(function() {
'use strict';
console.log('🚀 Optimizely injection script starting...');
console.log('📍 Current URL:', window.location.href);
console.log('📊 Document ready state:', document.readyState);
// Function to inject the Optimizely script
function injectOptimizelyScript() {
// [WARNING] You must disable 'Mask descriptive names in project code and third-party' in this project's settings for this to work! See here https://support.optimizely.com/hc/en-us/articles/4410284343181-Project-Settings-Privacy#01H84ETPDDFDXMTYDWWAX92EKG
var decisionObject = window.optimizely.get('state').getDecisionObject({
campaignId: campaignId,
shouldCleanString: true
});
var utils = window.optimizely.get('utils');
function sendToAnalyticsProvider() {
(function() {
'use strict';
console.log('🚀 Zaius injection script starting...');
console.log('📍 Current URL:', window.location.href);
console.log('📊 Document ready state:', document.readyState);
// Function to inject the Zaius script
function injectZaiusScript() {
console.log('🔧 Starting Zaius script injection process...');
// Constant for consistent event naming
const OPTIMIZELY_EVENT_NAME = 'Optimizely_Experiment';
// Helper function to safely retrieve the FullStory API
// You may want to add code to wait for it to be available
function _fs() {
const fsNamespace = window['_fs_namespace'];
const fsApi = fsNamespace && window[fsNamespace];
return typeof fsApi === 'function' ? fsApi : () => {};
}
function getUserInfo(user_id){
// Add logic to check if (store_id_boolean is in local storage and not expired value)
fetch('https://tapi.optimizely.com/api/js/odds/project/<project_id>?project=<project_id>&c_user_id=' + user_id).then(function (response) {
// The API call was successful!
return response.json();
}).then(function (data) {
// Recommended to cache this user data for a period of time so you are not making requests for user info on every page load
return data
{
"plugin_type": "widget",
"name": "Optimizely Product Recommendations",
"edit_page_url": "https://p13n.opti-demo.online/",
"form_schema": [
{
"name": "header",
"options": null,
"label": "Header Text",
"default_value": "You might also love",
import { enums } from '@optimizely/optimizely-sdk';
// import your third-party analytics integration here
///////////////////////////////////////////
// SET UP DECISION NOTIFICATION LISTENER //
///////////////////////////////////////////
const onDecision = ({decisionType, userId, attributes, decisionInfo}) => {
if(decisionInfo['decisionEventDispatched']){
// This assumes the userContext is instantiated
// Ensure Contentsquare is available
async function checkIPAddress() {
// Using a public IP API service to get the visitor's IP
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
const visitorIP = data.ip;
return visitorIP
}