Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Analytics Coffee Break: On Monday, January 30 at 10am PT, the NOAM User Group led by Jennifer Dungan and Jeff Bloomer will be joining us to answer your Analytics related questions. To register and for more information, follow the link to the right.
SOLVED

Write custom code

Avatar

Level 4

How do I write the custom code to compare the build date and time for Adobe Launch and compare that with current time as shown in below article? Should I use IIFE?

 

  • Here, you will need to write custom code that checks for the value of _satellite.buildInfo.buildDate(this denotes the publishing time of your web property) and compares it with the current time.

 

  • If the difference between the two is less than an hour(you can customize it as necessary), send event100 in the page view server call.

 

Article Link : https://www.linkedin.com/pulse/get-adobe-launch-publish-notifications-from-analytics-naman-sachdeva/

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

To add to the other answer, if you are looking for help with the actual script, there are a few things to consider...

 

_satellite.buildInfo.buildDate will return a string, so you will need to parse it to a date to do math on the object.

var buildDate = Date.parse(_satellite.buildInfo.buildDate);

 

The other thing you should be aware of is that getting the current date with JS will take the user's time, and IF that user has their time set incorrectly could result in false positives... and you would be surprised how many people have the time set incorrectly...

 

Also, if you deploy your code at 10:30, and you are looking for deployments in the last hour... you will get alerts for both the 10-11 hour AND the 11-12 hour; since you will have page views between 10:30 and 11 (capturing the first analytics hourly check) and page views between 11 and 11:30 (still withing an hour of the deployment and in the second analytics hourly check). 

 

 

 

But essentially you would need to write something like:

// Get the Dates
var buildDate = Date.parse(_satellite.buildInfo.buildDate);
var currentDate = new Date();

// Calculate the difference and convert milliseconds into more usable data
var difference = (date - buildDate);
var seconds = Math.floor(difference / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);

// Check if the difference is less than 1 hour
var recentBuild = false;
if (hours <= 1){
  recentBuild = true;
}

Note, I used "recentBuild" boolean instead of setting the event directly here... since I don't know your current setup, I don't want to potentially advise you on something that might overwrite your other events.

 

If this is in a Data Element, you can add a "return recentBuild;" to the end... then use the true/false status to set your event... 

 

If you add this into the custom code area of your "Set Variables", you could potentially set the event right here with something like:

s.events += ",event100";

 

This will append event100 to the already set event value.

View solution in original post

4 Replies

Avatar

Community Advisor

You can write it in the custom code section of the Adobe Analytics > Set Variables action. You don't need to use IIFE. Launch will encapsulate it appropriately.

Avatar

Correct answer by
Community Advisor

To add to the other answer, if you are looking for help with the actual script, there are a few things to consider...

 

_satellite.buildInfo.buildDate will return a string, so you will need to parse it to a date to do math on the object.

var buildDate = Date.parse(_satellite.buildInfo.buildDate);

 

The other thing you should be aware of is that getting the current date with JS will take the user's time, and IF that user has their time set incorrectly could result in false positives... and you would be surprised how many people have the time set incorrectly...

 

Also, if you deploy your code at 10:30, and you are looking for deployments in the last hour... you will get alerts for both the 10-11 hour AND the 11-12 hour; since you will have page views between 10:30 and 11 (capturing the first analytics hourly check) and page views between 11 and 11:30 (still withing an hour of the deployment and in the second analytics hourly check). 

 

 

 

But essentially you would need to write something like:

// Get the Dates
var buildDate = Date.parse(_satellite.buildInfo.buildDate);
var currentDate = new Date();

// Calculate the difference and convert milliseconds into more usable data
var difference = (date - buildDate);
var seconds = Math.floor(difference / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);

// Check if the difference is less than 1 hour
var recentBuild = false;
if (hours <= 1){
  recentBuild = true;
}

Note, I used "recentBuild" boolean instead of setting the event directly here... since I don't know your current setup, I don't want to potentially advise you on something that might overwrite your other events.

 

If this is in a Data Element, you can add a "return recentBuild;" to the end... then use the true/false status to set your event... 

 

If you add this into the custom code area of your "Set Variables", you could potentially set the event right here with something like:

s.events += ",event100";

 

This will append event100 to the already set event value.

Avatar

Level 4

Thank you so much for this detailed answer!! I appreciate it. Will give it a shot for test property and see how it is looking and then implement it across all other properties.