Created
July 13, 2018 19:38
-
-
Save RiFi2k/9b58824f615e51cbfc0b3cef69261e9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 = ["https://itunes.apple.com/us/album/love-stuff/941366731"]; | |
// Create a new SMEAppleMusic object with your parameters | |
let sm = new SMEAppleMusic({ | |
ae: { | |
ae: '7d966967c22fe575eae042270621e3c2f218f9800e9d9a320a8ccb08322ccecd', | |
brand_id: '3443740', | |
segment_id: '27439', | |
activities: '{"actions":{"presave":12631},"mailing_list_optins":{"a0S61000001YpvzEAC":12632}}' | |
}, | |
am: { | |
dev_token: '', | |
save_mode: 'playlist', | |
custom_playlist_name: 'Elle King - Music', | |
resources: { | |
playlists: AmkPlaylists, | |
albums: AmkAlbums | |
} | |
}, | |
sf: { | |
form: '23120', | |
default_mailing_list: 'a0S61000001YpvzEAC' | |
}, | |
smf: { | |
campaign_id: '23120', | |
campaign_key: '0ffe87aee7591380cd989d13a8788ff9' | |
} | |
}); | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment