Skip to content

Instantly share code, notes, and snippets.

@RiFi2k
Created January 31, 2019 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RiFi2k/a525dbdec6f1463e5427d0fec932918c to your computer and use it in GitHub Desktop.
Save RiFi2k/a525dbdec6f1463e5427d0fec932918c to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Example Add to Library Button</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>
<body>
<div class="container mt-5">
<form id="apple_music_form">
<label for="apple_music_email_address">Email Address</label>
<div class="input-group mb-3">
<input id="apple_music_email_address" type="text" class="form-control" placeholder="Email Address" value="" required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit">Go</button>
</div>
</div>
</form>
</div>
<script src="https://obs.smehost.net/formssonymusicfanscom-appirioprod/apple-music/v1/amk.js"></script>
<script>
// Wrap your logic in the musickitloaded event
document.addEventListener('musickitloaded', function () {
let AmkPlaylists = [];
let AmkAlbums = [];
// Create a new SMEAppleMusic object with your parameters
let sm = new SMEAppleMusic({
ae: {
ae: '08437736b7852d630abdb0b0816ead312d19026cc1fedc2475ddc4cfda6efb86',
brand_id: '3443455',
segment_id: '165909',
activities: '{"actions":{"presave":17618},"mailing_list_optins":{"a0S61000001mDmJEAU":17690}}'
},
am: {
dev_token: '',
save_mode: 'library',
custom_playlist_name: '',
resources: {
playlists: AmkPlaylists,
albums: AmkAlbums
}
},
sf: {
form: '32468',
default_mailing_list: 'a0S61000001mDmJEAU'
},
smf: {
campaign_id: '32468',
campaign_key: '520405e891ad5134119542e5d050ce28'
}
});
document.getElementById('apple_music_form').addEventListener('submit', function (e) {
e.preventDefault();
// Grab the email address value
const email = document.getElementById('apple_music_email_address').value;
// Pass the email address and opt in status
// This can be true or false depending on if the user is forced into the list, or chooses via a checkbox or similar.
sm.doActions(email, true).then(function (res) {
// Complete - handle your logic here
}).catch(function (err) {
// Error - handle your logic here
});
});
});
</script>
<script src="https://js-cdn.music.apple.com/musickit/v1/musickit.js"></script>
</body>
</html>
c7d4f0277f039e591a43aad971063a52
API KEY
3443455
BRAND ID
165909
SEGMENT ID
{"actions":{"presave":17618},"mailing_list_optins":{"a0S61000001mDmJEAU":17690}}
ACTIVITIES
https://sme.theappreciationengine.com/framework/js/486?segment=165909
<!-- OPTIONAL: Place this code on your return URL to use the AE login callback function -->
<script type="text/javascript">
let SMEPreSave = {
state: null,
spotify_user: null,
url_vars: [],
getURLVars: function (callback, form_id) {
let hash;
let hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (let i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
this.url_vars.push(hash[0]);
this.url_vars[hash[0]] = hash[1];
}
this.state = 'state' in this.url_vars ? this.url_vars['state'] : null;
this.ae_member_id = 'ae_member_id' in this.url_vars ? this.url_vars['ae_member_id'] : null;
this.spotify_user = 'spotify_user' in this.url_vars ? this.url_vars['spotify_user'] : null;
this.deezer_user = 'deezer_user' in this.url_vars ? this.url_vars['deezer_user'] : null;
this.message = 'message' in this.url_vars ? this.url_vars['message'] : null;
if (typeof callback === 'function') {
callback(this.state, this.ae_member_id, this.spotify_user, this.deezer_user, this.message);
}
}
};
/* String state
* The status of the pre-save.
* Int ae_member_id
* The Appreciation Engine member ID. This can be passed to the forms processor.
* String spotify_user
* An encrypted string identifying the Spotify user. Can be passed to the pre-save forms processor.
* String deezery_user
* An encrypted string identifying the Deezer user. Can be passed to the pre-save forms processor.
*/
SMEPreSave.getURLVars(function (state, ae_member_id, spotify_user, deezer_user, message) {
// Check the state of the pre-save. If it was successful, the state will either be success or thank-you.
if (state === 'success' || state === 'thank-you') {
// Do your thank you logic here.
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment